Thanks to visit codestin.com
Credit goes to github.com

Skip to content

csvcut: Memory allocated in Strndup() is never free'd? #4

@bobhairgrove

Description

@bobhairgrove

Related to this issue: rgamble/libcsv#3

The results below were obtained AFTER adding a call to csv_free() at the end of csv_fini() in libcsv.c.

Sample file:
my_test.csv.zip

bob@mylaptop:~/code/CSV/csvcut/build/Release$ valgrind --leak-check=full ./csvcut -f 1 /home/bob/libcsv-master/tests/my_test.csv
==4783== Memcheck, a memory error detector
==4783== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==4783== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==4783== Command: ./csvcut -f 1 /home/bob/libcsv-master/tests/my_test.csv
==4783== 
"lastname"
"Doe"
"Lamb"
"Doe"
"Lamb"
(...snip...)
==4783== HEAP SUMMARY:
==4783==     in use at exit: 34 bytes in 2 blocks
==4783==   total heap usage: 22 allocs, 20 frees, 6,444 bytes allocated
==4783== 
==4783== 2 bytes in 1 blocks are definitely lost in loss record 1 of 2
==4783==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4783==    by 0x401D88: xmalloc (in /home/bob/code/CSV/csvcut/build/Release/csvcut)
==4783==    by 0x401E84: Strndup (in /home/bob/code/CSV/csvcut/build/Release/csvcut)
==4783==    by 0x4018EE: field_spec_cb1 (in /home/bob/code/CSV/csvcut/build/Release/csvcut)
==4783==    by 0x402119: csv_fini (in /home/bob/code/CSV/csvcut/build/Release/csvcut)
==4783==    by 0x4017E3: process_field_specs (in /home/bob/code/CSV/csvcut/build/Release/csvcut)
==4783==    by 0x400EDD: main (in /home/bob/code/CSV/csvcut/build/Release/csvcut)
==4783== 
==4783== LEAK SUMMARY:
==4783==    definitely lost: 2 bytes in 1 blocks
==4783==    indirectly lost: 0 bytes in 0 blocks
==4783==      possibly lost: 0 bytes in 0 blocks
==4783==    still reachable: 32 bytes in 1 blocks
==4783==         suppressed: 0 bytes in 0 blocks
==4783== Reachable blocks (those to which a pointer was found) are not shown.
==4783== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==4783== 
==4783== For counts of detected and suppressed errors, rerun with: -v
==4783== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions