Etant assez surpris des résultats de asan pour certains tests comme alloc-missing-delete, je l'ai relancé sur mon ubuntu 18 avec g++7.5 et un clang++ 13 (compilé main), avec $CXXFLAGS='-fsanitize=address -g -fno-omit-frame-pointer'. Les deux voient la fuite de mémoire
# avec g++
=================================================================
==301==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 4 byte(s) in 1 object(s) allocated from:
#0 0x7f54ad2ff448 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0448)
#1 0x5576a8634852 in main /home/moi/dev/tests/c++/alloc-missing-delete.cpp:3
#2 0x7f54ace4fc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)
SUMMARY: AddressSanitizer: 4 byte(s) leaked in 1 allocation(s).
# avec clang++
=================================================================
==1267==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 4 byte(s) in 1 object(s) allocated from:
#0 0x4c8c5d in operator new(unsigned long) /home/moi/local/clang/src/llvm/compiler-rt/lib/asan/asan_new_delete.cpp:99:3
#1 0x4cb57f in main /home/moi/dev/tests/c++/alloc-missing-delete.cpp:3:18
#2 0x7f5ff312cc86 in __libc_start_main /build/glibc-uZu3wS/glibc-2.27/csu/../csu/libc-start.c:310
SUMMARY: AddressSanitizer: 4 byte(s) leaked in 1 allocation(s).
Au passage, clang-tidy voit la fuite aussi:
2 warnings generated.
/home/moi/dev/tests/c++/alloc-missing-delete.cpp:3:10: warning: Value stored to 'value' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
int* value = new int(argc);
^
/home/moi/dev/tests/c++/alloc-missing-delete.cpp:3:10: note: Value stored to 'value' during its initialization is never read
/home/moi/dev/tests/c++/alloc-missing-delete.cpp:7:5: warning: Potential leak of memory pointed to by 'value' [clang-analyzer-cplusplus.NewDeleteLeaks]
return 0;
^
/home/moi/dev/tests/c++/alloc-missing-delete.cpp:3:18: note: Memory is allocated
int* value = new int(argc);
^
/home/moi/dev/tests/c++/alloc-missing-delete.cpp:7:5: note: Potential leak of memory pointed to by 'value'
return 0;
^
# Résultats différents pour asan
Posté par lmg HS (site web personnel) . En réponse au journal Comparatif d'outils d'analyse mémoire. Évalué à 2. Dernière modification le 21 avril 2022 à 11:21.
Etant assez surpris des résultats de asan pour certains tests comme alloc-missing-delete, je l'ai relancé sur mon ubuntu 18 avec g++7.5 et un clang++ 13 (compilé main), avec
$CXXFLAGS='-fsanitize=address -g -fno-omit-frame-pointer'. Les deux voient la fuite de mémoireAu passage, clang-tidy voit la fuite aussi: