Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak fix #1701

Merged
merged 1 commit into from
Jul 25, 2019
Merged

memory leak fix #1701

merged 1 commit into from
Jul 25, 2019

Conversation

LeeYoung624
Copy link
Contributor

Pointer path points to a memory which is malloced in the while loop, but it's not freed before continue

@felixhandte
Copy link
Contributor

Hey, great catch! This is obviously a leak by inspection, and I can in fact trigger it in valgrind, by compressing a directory that has a symlink in it:

felixh@vali:~/prog/zstd (dev)$ ls -lh tmp/
total 4.0K
-rw-rw-r-- 1 felixh felixh 3 Jul 25 11:46 a
lrwxrwxrwx 1 felixh felixh 1 Jul 25 11:46 a.sl -> a
felixh@vali:~/prog/zstd (dev)$ valgrind --leak-check=full ./zstd -r tmp
==20602== Memcheck, a memory error detector
==20602== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==20602== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==20602== Command: ./zstd -r tmp
==20602== 
Warning : tmp/a.sl is a symbolic link, ignoring
tmp/a                :533.33%   (     3 =>     16 bytes, tmp/a.zst)            
==20602== 
==20602== HEAP SUMMARY:
==20602==     in use at exit: 48 bytes in 2 blocks
==20602==   total heap usage: 16 allocs, 14 frees, 330,405 bytes allocated
==20602== 
==20602== 9 bytes in 1 blocks are definitely lost in loss record 1 of 2
==20602==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20602==    by 0x1D7AD8: UTIL_prepareFileList (in /home/felixh/prog/zstd/zstd)
==20602==    by 0x1D7F28: UTIL_createFileList (in /home/felixh/prog/zstd/zstd)
==20602==    by 0x10BFB9: main (in /home/felixh/prog/zstd/zstd)
==20602== 
==20602== LEAK SUMMARY:
==20602==    definitely lost: 9 bytes in 1 blocks
==20602==    indirectly lost: 0 bytes in 0 blocks
==20602==      possibly lost: 0 bytes in 0 blocks
==20602==    still reachable: 39 bytes in 1 blocks
==20602==         suppressed: 0 bytes in 0 blocks
==20602== Reachable blocks (those to which a pointer was found) are not shown.
==20602== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==20602== 
==20602== For counts of detected and suppressed errors, rerun with: -v
==20602== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
felixh@vali:~/prog/zstd (dev)$ 

This fix is pretty obviously right, I'm going to merge it into the release in progress now. Thanks for your contribution!

@felixhandte felixhandte merged commit d95ac34 into facebook:dev Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants