aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-08-05 15:29:04 +0000
committersaturneric <[email protected]>2024-08-05 15:29:04 +0000
commit512c2198507bcfa4367e39163edf8b626a3008a9 (patch)
tree7039371d43fe1f9989856d504f7a42c3b40ea6eb
parentfix: addressing some of the significant deficiencies identified (diff)
downloadGpgFrontend-512c2198507bcfa4367e39163edf8b626a3008a9.tar.gz
GpgFrontend-512c2198507bcfa4367e39163edf8b626a3008a9.zip
fix: remove mimalloc from source
Too bad, under Flatpak or even under Windows, this library can cause the program to crash. The reason for this is that there are some places that do not override the memory allocation method, but this does not guarantee that the mimalloc library will be loaded first in some environments (especially Flatpak) so I think it would be better to let the user install it themselves rather than include this library. Then override all mallocs as needed, which is easy to do. Sacrificing some of the security of the default state for the stability of the program feels necessary to me.
-rw-r--r--.github/workflows/codeql-analysis.yml8
-rw-r--r--.github/workflows/release-qt5.yml20
-rw-r--r--.github/workflows/release.yml20
-rw-r--r--src/CMakeLists.txt13
-rw-r--r--src/core/CMakeLists.txt5
-rw-r--r--src/core/function/SecureMemoryAllocator.cpp30
-rw-r--r--src/core/thread/Task.cpp3
7 files changed, 7 insertions, 92 deletions
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index b1a100eb..9b11ad8d 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -83,14 +83,6 @@ jobs:
sudo make install
cd ${{github.workspace}}
- - name: Build mimalloc (Linux)
- run: |
- cd ${{github.workspace}}/third_party/mimalloc
- mkdir build && cd build
- cmake -G Ninja -DMI_SECURE=ON ..
- ninja
- sudo ninja install
-
- name: Build googletest (Linux)
run: |
cd ${{github.workspace}}/third_party/googletest
diff --git a/.github/workflows/release-qt5.yml b/.github/workflows/release-qt5.yml
index 1102379c..7870159e 100644
--- a/.github/workflows/release-qt5.yml
+++ b/.github/workflows/release-qt5.yml
@@ -138,26 +138,6 @@ jobs:
cd ${{github.workspace}}
if: matrix.os == 'ubuntu-20.04'
- - name: Build mimalloc (Linux)
- run: |
- git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
- cd ${{github.workspace}}/third_party/mimalloc
- mkdir build && cd build
- cmake -G Ninja -DMI_SECURE=ON ..
- ninja
- sudo ninja install
- if: matrix.os == 'ubuntu-20.04'
-
- - name: Build mimalloc (Windows)
- shell: msys2 {0}
- run: |
- git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
- cd ${{github.workspace}}/third_party/mimalloc
- mkdir build && cd build
- cmake -G Ninja -DMI_SECURE=ON -DCMAKE_INSTALL_PREFIX=$MSYSTEM_PREFIX .. && ninja
- ninja install
- if: matrix.os == 'windows-2019'
-
- name: Build googletest (Linux)
run: |
git clone --depth 1 --branch v1.15.0 https://github.com/google/googletest.git ${{github.workspace}}/third_party/googletest
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 47bf1f5d..e6542d4d 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -164,26 +164,6 @@ jobs:
make install
if: matrix.os == 'windows-2019'
- - name: Build mimalloc (Linux)
- run: |
- git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
- cd ${{github.workspace}}/third_party/mimalloc
- mkdir build && cd build
- cmake -G Ninja -DMI_SECURE=ON ..
- ninja
- sudo ninja install
- if: matrix.os == 'ubuntu-20.04'
-
- - name: Build mimalloc (Windows)
- shell: msys2 {0}
- run: |
- git clone --depth 1 --branch v2.1.7 https://github.com/microsoft/mimalloc.git ${{github.workspace}}/third_party/mimalloc
- cd ${{github.workspace}}/third_party/mimalloc
- mkdir build && cd build
- cmake -G Ninja -DMI_SECURE=ON -DCMAKE_INSTALL_PREFIX=$MSYSTEM_PREFIX .. && ninja
- ninja install
- if: matrix.os == 'windows-2019'
-
- name: Build googletest (Linux)
run: |
git clone --depth 1 --branch v1.15.0 https://github.com/google/googletest.git ${{github.workspace}}/third_party/googletest
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 08b6e3a1..51239a4a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -55,11 +55,6 @@ endif()
find_package(OpenSSL REQUIRED)
-# mimalloc
-if(NOT APPLE)
- find_package(mimalloc REQUIRED)
-endif()
-
# Set Build Information
configure_file(${CMAKE_SOURCE_DIR}/src/GpgFrontend.h.in ${CMAKE_SOURCE_DIR}/src/GpgFrontend.h @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/src/GpgFrontendBuildInfo.h.in ${CMAKE_SOURCE_DIR}/src/GpgFrontendBuildInfo.h @ONLY)
@@ -284,14 +279,6 @@ if(BUILD_APPLICATION AND MINGW)
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
unset(_libDllPath)
- file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libmimalloc*.dll")
- list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
-
- unset(_libDllPath)
- file(GLOB _libDllPath "${MSYS64_BIN_PATH}/mimalloc*.dll")
- list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
-
- unset(_libDllPath)
file(GLOB _libDllPath "${MSYS64_BIN_PATH}/libarchive*.dll")
list(APPEND ALL_RUNTIME_DEP_PATH_LIST ${_libDllPath})
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 81c3f08f..90409e22 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -50,11 +50,6 @@ generate_export_header(gpgfrontend_core EXPORT_FILE_NAME "${_export_file}")
# compile definitions
target_compile_definitions(gpgfrontend_core PRIVATE GF_CORE_PRIVATE)
-# mimalloc (except apple macos)
-if(NOT APPLE)
- target_link_libraries(gpgfrontend_core PUBLIC mimalloc)
-endif()
-
# qt-aes
target_sources(gpgfrontend_core PRIVATE
${CMAKE_SOURCE_DIR}/third_party/qt-aes/qaesencryption.cpp)
diff --git a/src/core/function/SecureMemoryAllocator.cpp b/src/core/function/SecureMemoryAllocator.cpp
index c24e13f2..47301038 100644
--- a/src/core/function/SecureMemoryAllocator.cpp
+++ b/src/core/function/SecureMemoryAllocator.cpp
@@ -28,42 +28,22 @@
#include "SecureMemoryAllocator.h"
-namespace GpgFrontend {
+#include <cstdlib>
-#if defined(__APPLE__) && defined(__MACH__)
+namespace GpgFrontend {
auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* {
- auto* addr = malloc(size);
+ auto* addr = std::malloc(size);
if (addr == nullptr) FLOG_F("malloc failed!");
return addr;
}
auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* {
- auto* addr = realloc(ptr, size);
+ auto* addr = std::realloc(ptr, size);
if (addr == nullptr) FLOG_F("realloc failed!");
return addr;
}
-void SecureMemoryAllocator::Deallocate(void* p) { free(p); }
-
-#else
-
-#include <mimalloc.h>
-
-auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* {
- auto* addr = mi_malloc(size);
- if (addr == nullptr) FLOG_F("malloc failed!");
- return addr;
-}
-
-auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* {
- auto* addr = mi_realloc(ptr, size);
- if (addr == nullptr) FLOG_F("realloc memory failed!");
- return addr;
-}
-
-void SecureMemoryAllocator::Deallocate(void* p) { mi_free(p); }
-
-#endif
+void SecureMemoryAllocator::Deallocate(void* p) { std::free(p); }
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp
index 7a0e76e8..71c3f7b2 100644
--- a/src/core/thread/Task.cpp
+++ b/src/core/thread/Task.cpp
@@ -164,7 +164,8 @@ class Task::Impl {
}
};
-Task::Task(QString name) : p_(new Impl(this, name)) {}
+Task::Task(QString name)
+ : p_(SecureCreateUniqueObject<Task::Impl>(this, name)) {}
Task::Task(TaskRunnable runnable, QString name, DataObjectPtr data_object)
: p_(SecureCreateUniqueObject<Impl>(this, runnable, name, data_object)) {}