Skip to content

Commit

Permalink
Merge pull request #318 from fboemer/fboemer/fix-free
Browse files Browse the repository at this point in the history
Fix clang alloc-dealloc-mismatch
  • Loading branch information
Wei Dai authored Apr 13, 2021
2 parents 44e954b + e1ab1f5 commit c289ac4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ if(SEAL_USE_INTEL_HEXL)
endif()
endif()

# [option] SEAL_USE_ADDRESS_SANITIZER (default: OFF)
option(SEAL_USE_ADDRESS_SANITIZER_OPTION_STR "Compiles and links with Address Sanitizer" OFF)
option(SEAL_USE_ADDRESS_SANITIZER ${SEAL_USE_ADDRESS_SANITIZER_OPTION_STR} OFF)
message(STATUS "SEAL_USE_ADDRESS_SANITIZER: ${SEAL_USE_ADDRESS_SANITIZER}")

if(SEAL_USE_ADDRESS_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
endif()

####################
# SEAL C++ library #
####################
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ The following options can be used with CMake to configure the build. The default
| SEAL_BUILD_SEAL_C | ON / **OFF** | Build the C wrapper library SEAL_C. This is used by the C# wrapper and most users should have no reason to build it. |
| SEAL_USE_CXX17 | **ON** / OFF | Set to `ON` to build Microsoft SEAL as C++17 for a positive performance impact. |
| SEAL_USE_INTRIN | **ON** / OFF | Set to `ON` to use compiler intrinsics for improved performance. CMake will automatically detect which intrinsics are available and enable them accordingly. |
| SEAL_USE_ADDRESS_SANITIZER | ON / *OFF* | Set to `ON` to enable [AddressSanitizer](https://github.com/google/sanitizers) for diagnosing memory corruption issues

As usual, these options can be passed to CMake with the `-D` flag.
For example, one could run
Expand Down
1 change: 1 addition & 0 deletions native/src/seal/util/clang.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cstdlib>
#define SEAL_MALLOC(size) \
static_cast<seal_byte *>((((size)&63) == 0) ? ::aligned_alloc(64, (size)) : std::malloc((size)))
#define SEAL_FREE(ptr) std::free(ptr)
#endif

// Are intrinsics enabled?
Expand Down
2 changes: 1 addition & 1 deletion native/src/seal/util/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace seal

// Allocate "size" bytes in memory and returns a seal_byte pointer
// If SEAL_USE_ALIGNED_ALLOC is defined, use _aligned_malloc and ::aligned_alloc (or std::malloc)
// Use `new sealbytes[size]` as fallback
// Use `new seal_byte[size]` as fallback
#ifndef SEAL_MALLOC
#define SEAL_MALLOC(size) (new seal_byte[size])
#endif
Expand Down

0 comments on commit c289ac4

Please sign in to comment.