@@ -320,6 +320,109 @@ allocated. This is because by default the addon is compiled without
320320the debug symbols which Valgrind needs to be able to provide more
321321information.
322322
323+ It is possible to hide leaks related to Node.js itself in future Valgrind runs
324+ using the suppression feature of Valgrind.
325+
326+ # # Generating a Valgrind suppression file
327+
328+ Valgrind uses suppression files to hide issues found from the summary. Generate
329+ a log file with embedded suppressions using the ` --gen-suppressions` and
330+ ` --log-file` flags:
331+
332+ ` ` ` bash
333+ valgrind --leak-check=full \
334+ --gen-suppressions=all \
335+ --log-file=./valgrind-out.txt \
336+ node hello.js
337+ ` ` `
338+
339+ Valgrind will save the output to the log file specified. After each heap in the
340+ summary, Valgrind will include a suppression record: a structure that Valgrind
341+ can use to ignore specific memory issues. Suppression records can be saved to a
342+ suppression file which Valgrind can use in subsequent executions to hide various
343+ memory errors. This is an example of the suppression records from the previous
344+ call:
345+
346+ ` ` ` text
347+ {
348+ < insert_a_suppression_name_here>
349+ Memcheck:Value8
350+ obj:/home/kevin/.nvm/versions/node/v12.14.1/bin/node
351+ obj:/home/kevin/.nvm/versions/node/v12.14.1/bin/node
352+ obj:/home/kevin/.nvm/versions/node/v12.14.1/bin/node
353+ obj:/home/kevin/.nvm/versions/node/v12.14.1/bin/node
354+ obj:/home/kevin/.nvm/versions/node/v12.14.1/bin/node
355+ obj:/home/kevin/.nvm/versions/node/v12.14.1/bin/node
356+ obj:/home/kevin/.nvm/versions/node/v12.14.1/bin/node
357+ obj:/home/kevin/.nvm/versions/node/v12.14.1/bin/node
358+ obj:/home/kevin/.nvm/versions/node/v12.14.1/bin/node
359+ fun:_ZN2v88internal12_GLOBAL__N_16InvokeEPNS0_7IsolateERKNS1_12InvokeParamsE
360+ fun:_ZN2v88internal9Execution4CallEPNS0_7IsolateENS0_6HandleINS0_6ObjectEEES6_iPS6_
361+ fun:_ZN2v88Function4CallENS_5LocalINS_7ContextEEENS1_INS_5ValueEEEiPS5_
362+ }
363+ {
364+ < insert_a_suppression_name_here>
365+ Memcheck:Leak
366+ match-leak-kinds: definite
367+ fun:_Znwm
368+ fun:napi_module_register
369+ fun:call_init.part.0
370+ fun:call_init
371+ fun:_dl_init
372+ fun:_dl_catch_exception
373+ fun:dl_open_worker
374+ fun:_dl_catch_exception
375+ fun:_dl_open
376+ fun:dlopen_doit
377+ fun:_dl_catch_exception
378+ fun:_dl_catch_error
379+ fun:_dlerror_run
380+ }
381+ {
382+ < insert_a_suppression_name_here>
383+ Memcheck:Leak
384+ match-leak-kinds: possible
385+ fun:calloc
386+ fun:allocate_dtv
387+ fun:_dl_allocate_tls
388+ fun:allocate_stack
389+ fun:pthread_create@@GLIBC_2.2.5
390+ fun:_ZN4node9inspector5Agent5StartERKSsRKNS_12DebugOptionsESt10shared_ptrINS_8HostPortEEb
391+ fun:_ZN4node11Environment19InitializeInspectorESt10unique_ptrINS_9inspector21ParentInspectorHandleESt14default_deleteIS3_EE
392+ fun:_ZN4node16NodeMainInstance21CreateMainEnvironmentEPi
393+ fun:_ZN4node16NodeMainInstance3RunEv
394+ fun:_ZN4node5StartEiPPc
395+ fun:(below main)
396+ }
397+ ` ` `
398+
399+ Create a file (eg. ` node-12.14.1.supp` ) with the contents of the suppression
400+ records, and run Valgrind with the suppression file previously created:
401+
402+ ` ` ` bash
403+ valgrind --leak-check=full \
404+ --suppressions=./node-12.14.1.supp \
405+ node hello.js
406+ ` ` `
407+
408+ Now, the Valgrind leak summary for suppressed issues are only mentioned as
409+ ` suppressed` in the leak summary:
410+
411+ ` ` ` console
412+ ==12471== HEAP SUMMARY:
413+ ==12471== in use at exit: 8,067 bytes in 31 blocks
414+ ==12471== total heap usage: 16,482 allocs, 16,451 frees, 17,255,689 bytes allocated
415+ ==12471==
416+ ==12471== LEAK SUMMARY:
417+ ==12471== definitely lost: 0 bytes in 0 blocks
418+ ==12471== indirectly lost: 0 bytes in 0 blocks
419+ ==12471== possibly lost: 0 bytes in 0 blocks
420+ ==12471== still reachable: 7,699 bytes in 29 blocks
421+ ==12471== of which reachable via heuristic:
422+ ==12471== multipleinheritance: 48 bytes in 1 blocks
423+ ==12471== suppressed: 368 bytes in 2 blocks
424+ ` ` `
425+
323426# # Enabling debug symbols to get more information
324427
325428Leaks may be either in addons or Node.js itself. The sections which
0 commit comments