Skip to content

Support building with address sanitizer#581

Merged
staticlibs merged 1 commit intoduckdb:mainfrom
staticlibs:asan_build
Mar 1, 2026
Merged

Support building with address sanitizer#581
staticlibs merged 1 commit intoduckdb:mainfrom
staticlibs:asan_build

Conversation

@staticlibs
Copy link
Copy Markdown
Collaborator

@staticlibs staticlibs commented Feb 26, 2026

This PR adds support for building JDBC driver with the address sanitizer enabled:

make sanitized

To run the sanitized binary libasan and libstdc++ must be preloaded:

export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libasan.so.8 /usr/lib/x86_64-linux-gnu/libstdc++.so.6"

If we add the following deliberately erratic snippet somewhere inside the JDBC driver:

int *x = reinterpret_cast<int*>(malloc(10 * sizeof(int*)));
free(x);
std::cout << x[5] << std::endl;

Then the execution will abort with something like the following:

=================================================================
==114481==ERROR: AddressSanitizer: heap-use-after-free on address 0x7bf5410abf14 at pc 0x7b83372124ac bp 0x7f85413fe070 sp 0x7f85413fe068
READ of size 4 at 0x7bf5410abf14 thread T1
    #0 0x7b83372124ab in _duckdb_jdbc_startup(JNIEnv_*, _jclass*, _jbyteArray*, unsigned char, _jobject*) duckdb-java/src/jni/duckdb_java.cpp:79:18
    #1 0x7b8337239880 in Java_org_duckdb_DuckDBNative_duckdb_1jdbc_1startup duckdb-java/src/jni/functions.cpp:9:30
    #2 0x7b852b3445d9  (<unknown module>)
[...]
==114481==ABORTING

Note that on successful run the JVM may print a lot of internal "leak" warnings, it may be necessary to prepare a suppression file to prevent this.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant