]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib:ldb: Fix memory leaks in ldb_kv_index.c
authorPetr Usoltsev <usoltsevpv@basealt.ru>
Tue, 3 Mar 2026 07:31:18 +0000 (15:31 +0800)
committerAnoop C S <anoopcs@samba.org>
Tue, 14 Jul 2026 06:18:36 +0000 (06:18 +0000)
The "rec" variable is allocated within the long-lived LDB memory
context, meaning it persists until the module is unloaded.
Previously, this resource was only freed upon the successful
execution of ldb_dn_compare().

If ldb_dn_compare fails, the allocated memory is leaked. This patch
ensures that the memory is properly released regardless of the
function's return status.

Signed-off-by: Petr Usoltsev <usoltsevpv@basealt.ru>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Autobuild-User(master): Anoop C S <anoopcs@samba.org>
Autobuild-Date(master): Tue Jul 14 06:18:36 UTC 2026 on atb-devel-224

lib/ldb/ldb_key_value/ldb_kv_index.c

index 7f5361fe63f9bd0e870a992249acb4fdab572fe6..9300d749f41b18bc10fe16118b59a9b591a91abd 100644 (file)
@@ -706,6 +706,7 @@ int ldb_kv_key_dn_from_idx(struct ldb_module *module,
                                TALLOC_FREE(rec);
                                break;
                        }
+                       TALLOC_FREE(rec);
                }
 
                /*
@@ -2874,6 +2875,7 @@ static int ldb_kv_index_add1(struct ldb_module *module,
                                TALLOC_FREE(list);
                                return LDB_ERR_CONSTRAINT_VIOLATION;
                        }
+                       TALLOC_FREE(rec);
                }
        }