Dan Williams <[email protected]> writes:

> On Tue, Feb 18, 2020 at 7:53 AM Vaibhav Jain <[email protected]> wrote:
>>
>> Presently main_handle_internal_command() will simply call exit() on
>> the return value from run_builtin(). This prevents release of allocated
>> contexts 'struct ndctl_ctx' or 'struct daxctl_ctx' when the main
>> thread exits.
>>
>
> There is ultimately no leak since process exit cleans up all
> resources. Does this address a functional problem, or is it just a
> hygiene fixup?

I am trying to implement support for a new dimm type in ndctl and was
trying to debug a potential memory leak via valgrind/memcheck when came
across this issue. Without this patch, memcheck reports lots of leaking
reachable memory at ndctl exit that made the task of isolating real leak
bit problematic.

Below are the run logs of a 'ndctl list' command without and with the
patch applied.

# Without the patch
$ valgrind --leak-check=full ndctl/.libs/ndctl list  
==132738== Memcheck, a memory error detector
==132738== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==132738== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==132738== Command: ndctl/.libs/ndctl list
==132738== 
==132738== 
==132738== HEAP SUMMARY:
==132738==     in use at exit: 16,564 bytes in 264 blocks
==132738==   total heap usage: 920 allocs, 656 frees, 466,916 bytes allocated
==132738== 
==132738== LEAK SUMMARY:
==132738==    definitely lost: 0 bytes in 0 blocks
==132738==    indirectly lost: 0 bytes in 0 blocks
==132738==      possibly lost: 0 bytes in 0 blocks
==132738==    still reachable: 16,564 bytes in 264 blocks
==132738==         suppressed: 0 bytes in 0 blocks
==132738== Reachable blocks (those to which a pointer was found) are not shown.
==132738== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==132738== 
==132738== For lists of detected and suppressed errors, rerun with: -s
==132738== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


# With the patch applied
$ valgrind --leak-check=full ndctl/.libs/ndctl list 
==132759== Memcheck, a memory error detector
==132759== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==132759== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==132759== Command: ndctl/.libs/ndctl list
==132759== 
==132759== 
==132759== HEAP SUMMARY:
==132759==     in use at exit: 0 bytes in 0 blocks
==132759==   total heap usage: 920 allocs, 920 frees, 466,916 bytes allocated
==132759== 
==132759== All heap blocks were freed -- no leaks are possible
==132759== 
==132759== For lists of detected and suppressed errors, rerun with: -s
==132759== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

-- 
Vaibhav Jain <[email protected]>
Linux Technology Center, IBM India Pvt. Ltd.
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to