Bug 15403 - smbget memory leak if failed to download files recursively
Summary: smbget memory leak if failed to download files recursively
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Tools (show other bugs)
Version: 4.18.3
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Jule Anger
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-27 09:12 UTC by Jones Syue
Modified: 2023-07-06 14:00 UTC (History)
1 user (show)

See Also:


Attachments
Patch (1.29 KB, patch)
2023-06-28 07:45 UTC, Volker Lendecke
jra: review+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jones Syue 2023-06-27 09:12:11 UTC
Using smbget to download files recursively (-R). 

If smbget found that a file is already existed in the destination, 
smbget would said 'File exists', return early, and 'newname' allocated 
memory is never freed, this is found by valgrind.

patch will follow.

# valgrind --leak-check=full --show-leak-kinds=definite smbget -R -U${ac}%${pw} smb://${ip}/src
==13050== Memcheck, a memory error detector
==13050== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==13050== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==13050== Command: smbget -R -Ujones%${pw} smb://127.0.0.1/src
==13050==
Using workgroup WORKGROUP, user jones
Can't open file: File exists
Failed to download /file: File exists
==13050==
==13050== HEAP SUMMARY:
==13050==     in use at exit: 121,424 bytes in 263 blocks
==13050==   total heap usage: 5,466 allocs, 5,203 frees, 927,883 bytes allocated
==13050==
==13050== 6 bytes in 1 blocks are definitely lost in loss record 6 of 151
==13050==    at 0x4C28B15: malloc (in /root/bin/valgrind-3.12.0/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==13050==    by 0x5B7E9D7: vasprintf (vasprintf.c:76)
==13050==    by 0x5B5D2C6: asprintf (asprintf.c:35)
==13050==    by 0x10BC29: smb_download_dir (smbget.c:211)
==13050==    by 0x10A549: main (smbget.c:1037)
==13050==
... <cut> ...
Comment 2 Jeremy Allison 2023-06-27 18:12:47 UTC
MR LGTM. I'll push once I get a second Team reviewer.
Comment 3 Samba QA Contact 2023-06-28 07:03:05 UTC
This bug was referenced in samba master:

afbed653526b572f7309e67ed742a76ef7b2b8ec
Comment 4 Volker Lendecke 2023-06-28 07:45:00 UTC
Created attachment 17959 [details]
Patch
Comment 5 Jeremy Allison 2023-06-28 16:07:37 UTC
Comment on attachment 17959 [details]
Patch

LGTM.
Comment 6 Jeremy Allison 2023-06-28 16:08:12 UTC
Re-assigning to Jule for inclusion in 4.18.next, 4.17.next.
Comment 7 Jule Anger 2023-06-28 20:02:36 UTC
Pushed to autobuild-v4-{18,17}-test.
Comment 8 Samba QA Contact 2023-06-28 21:04:05 UTC
This bug was referenced in samba v4-17-test:

88c24655c7966af129b679535f181c7779ce0eef
Comment 9 Samba QA Contact 2023-07-03 08:54:21 UTC
This bug was referenced in samba v4-18-test:

29c08b5891d984dad1935dbf1ac72c1bb384ff88
Comment 10 Jule Anger 2023-07-03 08:57:44 UTC
Closing out bug report.

Thanks!
Comment 11 Samba QA Contact 2023-07-05 11:35:37 UTC
This bug was referenced in samba v4-18-stable (Release samba-4.18.4):

29c08b5891d984dad1935dbf1ac72c1bb384ff88
Comment 12 Samba QA Contact 2023-07-06 14:00:48 UTC
This bug was referenced in samba v4-17-stable (Release samba-4.17.9):

88c24655c7966af129b679535f181c7779ce0eef