1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

s3: modules: gluster. Fix the error I made in preventing talloc leaks from a function.

file_lines_parse() plays horrible tricks with
the passed-in talloc pointers and the hierarcy
which makes freeing hard to get right.

As we know mem_ctx is freed by the caller, after
calling file_lines_parse don't free on exit and let the caller
handle it. This violates good Samba coding practice
but we know we're not leaking here.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14486

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>

Autobuild-User(master): Günther Deschner <gd@samba.org>
Autobuild-Date(master): Wed Nov 11 15:02:27 UTC 2020 on sn-devel-184
This commit is contained in:
Jeremy Allison 2020-11-10 10:18:18 -08:00 committed by Günther Deschner
parent 31c703766f
commit 457b49c678

View File

@ -315,15 +315,25 @@ static int check_for_write_behind_translator(TALLOC_CTX *mem_ctx,
return -1; return -1;
} }
/*
* file_lines_parse() plays horrible tricks with
* the passed-in talloc pointers and the hierarcy
* which makes freeing hard to get right.
*
* As we know mem_ctx is freed by the caller, after
* this point don't free on exit and let the caller
* handle it. This violates good Samba coding practice
* but we know we're not leaking here.
*/
lines = file_lines_parse(buf, lines = file_lines_parse(buf,
newlen, newlen,
&numlines, &numlines,
mem_ctx); mem_ctx);
if (lines == NULL || numlines <= 0) { if (lines == NULL || numlines <= 0) {
TALLOC_FREE(option);
TALLOC_FREE(buf);
return -1; return -1;
} }
/* On success, buf is now a talloc child of lines !! */
for (i=0; i < numlines; i++) { for (i=0; i < numlines; i++) {
if (strequal(lines[i], option)) { if (strequal(lines[i], option)) {
@ -338,15 +348,9 @@ static int check_for_write_behind_translator(TALLOC_CTX *mem_ctx,
"Please check the vfs_glusterfs(8) manpage for " "Please check the vfs_glusterfs(8) manpage for "
"further details.\n", "further details.\n",
volume); volume);
TALLOC_FREE(lines);
TALLOC_FREE(option);
TALLOC_FREE(buf);
return -1; return -1;
} }
TALLOC_FREE(lines);
TALLOC_FREE(option);
TALLOC_FREE(buf);
return 0; return 0;
} }