[PATCH 0/2] MR11081: Use _aligned_free instead of free for aligned allocations (ASan).
Followup of 6b1dfdd262 and bd24679337. ASan gets triggered by using free instead of _aligned_free. Reports can be seen here: [x86_64](https://gitlab.winehq.org/bernhardu/wine/-/jobs/273791/artifacts/browse/asan...) and [x86](https://gitlab.winehq.org/bernhardu/wine/-/jobs/273791/artifacts/browse/asan...) <details> <summary>Example report:</summary> ``` ==rsaenh_test.exe==508==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x02003a10 in thread T0 #0 0x785b5acb in free /home/runner/work/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_malloc_win.cpp:78:3 #1 0x784725fb in SymCryptCallbackFree /builds/bernhardu/wine/build64/../dlls/rsaenh/implglue.c:44:5 #2 0x7848b93a in SymCryptRsakeySetValueInternal /builds/bernhardu/wine/build64/../libs/symcrypt/lib/rsakey.c:1391:9 #3 0x7848c283 in SymCryptRsakeySetValue /builds/bernhardu/wine/build64/../libs/symcrypt/lib/rsakey.c:1411:12 #4 0x7847396a in import_public_key_impl /builds/bernhardu/wine/build64/../dlls/rsaenh/implglue.c:480:9 #5 0x784852ec in import_public_key /builds/bernhardu/wine/build64/../dlls/rsaenh/rsaenh.c:3265:11 #6 0x7847a83d in import_key /builds/bernhardu/wine/build64/../dlls/rsaenh/rsaenh.c:3504:20 #7 0x7847a642 in RSAENH_CPImportKey /builds/bernhardu/wine/build64/../dlls/rsaenh/rsaenh.c:3545:12 #8 0x7ade982a in CryptImportKey /builds/bernhardu/wine/build64/../dlls/advapi32/crypt.c:1832:6 #9 0x00401882 in test_RC4_salt /builds/bernhardu/wine/build64/../dlls/rsaenh/tests/rsaenh.c:4075:15 #10 0x0040101a in func_rsaenh /builds/bernhardu/wine/build64/../dlls/rsaenh/tests/rsaenh.c:4195:5 #11 0x0041d411 in run_test /builds/bernhardu/wine/build64/../include/wine/test.h:780:5 #12 0x0041cf2b in main /builds/bernhardu/wine/build64/../include/wine/test.h 0x02003a10 is located 16 bytes inside of 324-byte region [0x02003a00,0x02003b44) allocated by thread T0 here: #0 0x785b5bcb in malloc /home/runner/work/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_malloc_win.cpp:87:3 #1 0x7ab7e0b3 in _aligned_offset_malloc /builds/bernhardu/wine/build64/../dlls/msvcrt/heap.c:584:12 #2 0x7ab7e138 in _aligned_malloc /builds/bernhardu/wine/build64/../dlls/msvcrt/heap.c:606:12 #3 0x784725dd in SymCryptCallbackAlloc /builds/bernhardu/wine/build64/../dlls/rsaenh/implglue.c:39:12 #4 0x7848b979 in SymCryptRsakeySetValueInternal /builds/bernhardu/wine/build64/../libs/symcrypt/lib/rsakey.c:1228:24 #5 0x7848c283 in SymCryptRsakeySetValue /builds/bernhardu/wine/build64/../libs/symcrypt/lib/rsakey.c:1411:12 #6 0x7847396a in import_public_key_impl /builds/bernhardu/wine/build64/../dlls/rsaenh/implglue.c:480:9 #7 0x784852ec in import_public_key /builds/bernhardu/wine/build64/../dlls/rsaenh/rsaenh.c:3265:11 #8 0x7847a83d in import_key /builds/bernhardu/wine/build64/../dlls/rsaenh/rsaenh.c:3504:20 #9 0x7847a642 in RSAENH_CPImportKey /builds/bernhardu/wine/build64/../dlls/rsaenh/rsaenh.c:3545:12 #10 0x7ade982a in CryptImportKey /builds/bernhardu/wine/build64/../dlls/advapi32/crypt.c:1832:6 #11 0x00401882 in test_RC4_salt /builds/bernhardu/wine/build64/../dlls/rsaenh/tests/rsaenh.c:4075:15 #12 0x0040101a in func_rsaenh /builds/bernhardu/wine/build64/../dlls/rsaenh/tests/rsaenh.c:4195:5 #13 0x0041d411 in run_test /builds/bernhardu/wine/build64/../include/wine/test.h:780:5 #14 0x0041cf2b in main /builds/bernhardu/wine/build64/../include/wine/test.h SUMMARY: AddressSanitizer: bad-free /builds/bernhardu/wine/build64/../dlls/rsaenh/implglue.c:44:5 in SymCryptCallbackFree ``` </details> -- https://gitlab.winehq.org/wine/wine/-/merge_requests/11081
From: Bernhard Übelacker <bernhardu@mailbox.org> Followup of 6b1dfdd262. --- dlls/rsaenh/implglue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlls/rsaenh/implglue.c b/dlls/rsaenh/implglue.c index d4f1d5d4d23..c6b47b60ef8 100644 --- a/dlls/rsaenh/implglue.c +++ b/dlls/rsaenh/implglue.c @@ -41,7 +41,7 @@ void * SYMCRYPT_CALL SymCryptCallbackAlloc( SIZE_T size ) void SYMCRYPT_CALL SymCryptCallbackFree( void *ptr ) { - free( ptr ); + _aligned_free( ptr ); } void SYMCRYPT_CALL SymCryptRsaSelftest( void ) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11081
From: Bernhard Übelacker <bernhardu@mailbox.org> Followup of bd24679337. --- dlls/dssenh/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlls/dssenh/main.c b/dlls/dssenh/main.c index 2579af0055c..3f72aefd70e 100644 --- a/dlls/dssenh/main.c +++ b/dlls/dssenh/main.c @@ -90,7 +90,7 @@ void * SYMCRYPT_CALL SymCryptCallbackAlloc( SIZE_T size ) void SYMCRYPT_CALL SymCryptCallbackFree( void *ptr ) { - free( ptr ); + _aligned_free( ptr ); } SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptCallbackRandom( BYTE *buf, SIZE_T size ) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11081
Should we be then using _aligned_malloc()? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/11081#note_142351
On Sat Jun 6 15:57:09 2026 +0000, Nikolay Sivov wrote:
Should we be then using _aligned_malloc()? Ah, we already do. I was looking at older snapshot.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/11081#note_142352
participants (3)
-
Bernhard Übelacker -
Bernhard Übelacker (@bernhardu) -
Nikolay Sivov (@nsivov)