From a16477e6e62b5525f6d8ddc297da2ec1ac176acc Mon Sep 17 00:00:00 2001 From: Swen Schillig Date: Mon, 29 Jul 2019 15:27:58 +0200 Subject: [PATCH] registry: Free memory at the end of each loop run to prevent mem leak Found during torture test runs with enable address-sanitizer. Signed-off-by: Swen Schillig Reviewed-by: Volker Lendecke Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Thu Aug 8 06:44:12 UTC 2019 on sn-devel-184 --- source4/lib/registry/patchfile_preg.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source4/lib/registry/patchfile_preg.c b/source4/lib/registry/patchfile_preg.c index ba8ac3a5c38..1897e2c55f5 100644 --- a/source4/lib/registry/patchfile_preg.c +++ b/source4/lib/registry/patchfile_preg.c @@ -221,9 +221,6 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, char *buf_ptr; TALLOC_CTX *mem_ctx = talloc_init("reg_preg_diff_load"); WERROR ret = WERR_OK; - DATA_BLOB data = {NULL, 0}; - char *key = NULL; - char *value_name = NULL; buf = talloc_array(mem_ctx, char, buf_size); buf_ptr = buf; @@ -249,6 +246,9 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, /* Read the entries */ while(1) { uint32_t value_type, length; + char *key = NULL; + char *value_name = NULL; + DATA_BLOB data = {NULL, 0}; if (!W_ERROR_IS_OK(preg_read_utf16(fd, buf_ptr))) { break; @@ -372,13 +372,13 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, callbacks->add_key(callback_data, key); callbacks->set_value(callback_data, key, value_name, value_type, data); - } + } + TALLOC_FREE(key); + TALLOC_FREE(value_name); + data_blob_free(&data); } cleanup: close(fd); - talloc_free(data.data); - talloc_free(key); - talloc_free(value_name); - talloc_free(buf); + TALLOC_FREE(mem_ctx); return ret; } -- 2.47.3