Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

c++ - How to properly use valgrind in Qt based app

I am trying to check whether my Qt app has memory leaks. I tried using valgrind on example project avalible in QTCreator. It is GUI app which uses QMainWindow class. Valgrind found lot of leaks:

==6426== Memcheck, a memory error detector
==6426== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==6426== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==6426== Command: ./project
==6426== 
--6426-- WARNING: unhandled amd64-linux syscall: 315
--6426-- You may be able to write your own handler.
--6426-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--6426-- Nevertheless we consider this a bug.  Please report
--6426-- it at http://valgrind.org/support/bug_reports.html.
==6426== Invalid read of size 8
==6426==    at 0x40209E8: strncmp (strcmp.S:175)
==6426==    by 0x40066ED: is_dst (dl-load.c:209)
==6426==    by 0x4009A2E: _dl_dst_count (dl-load.c:246)
==6426==    by 0x4009A2E: expand_dynamic_string_token (dl-load.c:388)
==6426==    by 0x4009BE1: fillin_rpath (dl-load.c:460)
==6426==    by 0x4009F43: decompose_rpath.isra.0 (dl-load.c:631)
==6426==    by 0x400ACCE: cache_rpath (dl-load.c:673)
==6426==    by 0x400ACCE: cache_rpath (dl-load.c:654)
==6426==    by 0x400ACCE: _dl_map_object (dl-load.c:2074)
==6426==    by 0x400F504: openaux (dl-deps.c:64)
==6426==    by 0x60198B7: _dl_catch_exception (dl-error-skeleton.c:208)
==6426==    by 0x400F952: _dl_map_object_deps (dl-deps.c:248)
==6426==    by 0x4015D9F: dl_open_worker (dl-open.c:571)
==6426==    by 0x60198B7: _dl_catch_exception (dl-error-skeleton.c:208)
==6426==    by 0x40155F9: _dl_open (dl-open.c:837)
==6426==  Address 0x96046d9 is 9 bytes inside a block of size 15 alloc'd
==6426==    at 0x4A37ECB: malloc (vg_replace_malloc.c:307)
==6426==    by 0x401F53E: strdup (strdup.c:42)
==6426==    by 0x4009ED4: decompose_rpath.isra.0 (dl-load.c:606)
==6426==    by 0x400ACCE: cache_rpath (dl-load.c:673)
==6426==    by 0x400ACCE: cache_rpath (dl-load.c:654)
==6426==    by 0x400ACCE: _dl_map_object (dl-load.c:2074)
==6426==    by 0x400F504: openaux (dl-deps.c:64)
==6426==    by 0x60198B7: _dl_catch_exception (dl-error-skeleton.c:208)
==6426==    by 0x400F952: _dl_map_object_deps (dl-deps.c:248)
==6426==    by 0x4015D9F: dl_open_worker (dl-open.c:571)
==6426==    by 0x60198B7: _dl_catch_exception (dl-error-skeleton.c:208)
==6426==    by 0x40155F9: _dl_open (dl-open.c:837)
==6426==    by 0x8E2834B: dlopen_doit (dlopen.c:66)
==6426==    by 0x60198B7: _dl_catch_exception (dl-error-skeleton.c:208)
==6426== 
==6426== Invalid read of size 8
==6426==    at 0x40209E8: strncmp (strcmp.S:175)
==6426==    by 0x40066ED: is_dst (dl-load.c:209)
==6426==    by 0x40098AE: _dl_dst_substitute (dl-load.c:288)
==6426==    by 0x4009BE1: fillin_rpath (dl-load.c:460)
==6426==    by 0x4009F43: decompose_rpath.isra.0 (dl-load.c:631)
==6426==    by 0x400ACCE: cache_rpath (dl-load.c:673)
==6426==    by 0x400ACCE: cache_rpath (dl-load.c:654)
==6426==    by 0x400ACCE: _dl_map_object (dl-load.c:2074)
==6426==    by 0x400F504: openaux (dl-deps.c:64)
==6426==    by 0x60198B7: _dl_catch_exception (dl-error-skeleton.c:208)
==6426==    by 0x400F952: _dl_map_object_deps (dl-deps.c:248)
==6426==    by 0x4015D9F: dl_open_worker (dl-open.c:571)
==6426==    by 0x60198B7: _dl_catch_exception (dl-error-skeleton.c:208)
==6426==    by 0x40155F9: _dl_open (dl-open.c:837)
==6426==  Address 0x96046d9 is 9 bytes inside a block of size 15 alloc'd
==6426==    at 0x4A37ECB: malloc (vg_replace_malloc.c:307)
==6426==    by 0x401F53E: strdup (strdup.c:42)
==6426==    by 0x4009ED4: decompose_rpath.isra.0 (dl-load.c:606)
==6426==    by 0x400ACCE: cache_rpath (dl-load.c:673)
==6426==    by 0x400ACCE: cache_rpath (dl-load.c:654)
==6426==    by 0x400ACCE: _dl_map_object (dl-load.c:2074)
==6426==    by 0x400F504: openaux (dl-deps.c:64)
==6426==    by 0x60198B7: _dl_catch_exception (dl-error-skeleton.c:208)
==6426==    by 0x400F952: _dl_map_object_deps (dl-deps.c:248)
==6426==    by 0x4015D9F: dl_open_worker (dl-open.c:571)
==6426==    by 0x60198B7: _dl_catch_exception (dl-error-skeleton.c:208)
==6426==    by 0x40155F9: _dl_open (dl-open.c:837)
==6426==    by 0x8E2834B: dlopen_doit (dlopen.c:66)
==6426==    by 0x60198B7: _dl_catch_exception (dl-error-skeleton.c:208)
==6426== 
==6426== 
==6426== HEAP SUMMARY:
==6426==     in use at exit: 2,479,965 bytes in 27,792 blocks
==6426==   total heap usage: 332,697 allocs, 304,905 frees, 27,650,747 bytes allocated
==6426== 
==6426== LEAK SUMMARY:
==6426==    definitely lost: 6,760 bytes in 27 blocks
==6426==    indirectly lost: 4,492 bytes in 134 blocks
==6426==      possibly lost: 3,840 bytes in 33 blocks
==6426==    still reachable: 2,382,241 bytes in 26,924 blocks
==6426==                       of which reachable via heuristic:
==6426==                         length64           : 4,960 bytes in 82 blocks
==6426==                         newarray           : 2,096 bytes in 51 blocks
==6426==         suppressed: 0 bytes in 0 blocks
==6426== Rerun with --leak-check=full to see details of leaked memory
==6426== 
==6426== For lists of detected and suppressed errors, rerun with: -s
==6426== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

I am probably missing some options to set in valgrind, because I used 'pure' valgrind. The command I used: valgrind ./project. All tests I have done on Ubuntu 20.04. When I used valgrind built in QtCreator I got "37 issues were found", but they are not displayed in memcheck view.

question from:https://stackoverflow.com/questions/65626715/how-to-properly-use-valgrind-in-qt-based-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You will probably need to build Valgrind from source in order to get the sched_getattr syscall, which was added after 3.16.1 was released.

Extract from git blame.

6323fd5b coregrind/m_syswrap/syswrap-amd64-linux.c   (Mark Wielaard         2020-07-27 16:36:17 +0200 850)    LINXY(__NR_sched_getattr,     sys_sched_getattr),    // 315

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...