lib: Fix a potential error path memleak
authorVolker Lendecke <vl@samba.org>
Fri, 23 Jul 2021 06:27:37 +0000 (08:27 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 6 Aug 2021 17:22:30 +0000 (17:22 +0000)
Don't directly overwrite the pointer for a realloc. On failure, the
original pointer is still valid.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/data_blob.c

index 6dc58c495db663d1bff678fa08aa3f4e916d91df..4de645e850ab91fcc038966c5e6ae9293ee37d62 100644 (file)
@@ -212,9 +212,11 @@ _PUBLIC_ DATA_BLOB data_blob_const(const void *p, size_t length)
 **/
 _PUBLIC_ bool data_blob_realloc(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, size_t length)
 {
-       blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, length);
-       if (blob->data == NULL)
+       uint8_t *tmp = talloc_realloc(mem_ctx, blob->data, uint8_t, length);
+       if (tmp == NULL) {
                return false;
+       }
+       blob->data = tmp;
        blob->length = length;
        return true;
 }