summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-10-17 05:50:01 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:21:17 -0500
commit0cf42c464ea240c4e57cc5b0c31227a0c5f684d4 (patch)
treea653bace124443095808542cc4927ba2c6e10251 /source4/lib/ldb
parenta4137b50a7f34e78686aac57921752f9a6fd643e (diff)
downloadsamba-0cf42c464ea240c4e57cc5b0c31227a0c5f684d4.tar.gz
samba-0cf42c464ea240c4e57cc5b0c31227a0c5f684d4.tar.bz2
samba-0cf42c464ea240c4e57cc5b0c31227a0c5f684d4.zip
r19365: fixed a memory leak in the ldb attribute handling
(This used to be commit d7e07685164141f8fb2c2a6258e1fcb46ff9d06c)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/common/ldb_attributes.c14
-rw-r--r--source4/lib/ldb/include/ldb.h3
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_cache.c10
3 files changed, 19 insertions, 8 deletions
diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c
index c8a7909b4c..2d9f0e6cf8 100644
--- a/source4/lib/ldb/common/ldb_attributes.c
+++ b/source4/lib/ldb/common/ldb_attributes.c
@@ -39,6 +39,7 @@ int ldb_set_attrib_handlers(struct ldb_context *ldb,
const struct ldb_attrib_handler *handlers,
unsigned num_handlers)
{
+ int i;
struct ldb_attrib_handler *h;
h = talloc_realloc(ldb, ldb->schema.attrib_handlers,
struct ldb_attrib_handler,
@@ -50,6 +51,16 @@ int ldb_set_attrib_handlers(struct ldb_context *ldb,
ldb->schema.attrib_handlers = h;
memcpy(h + ldb->schema.num_attrib_handlers,
handlers, sizeof(*h) * num_handlers);
+ for (i=0;i<num_handlers;i++) {
+ if (h[ldb->schema.num_attrib_handlers+i].flags & LDB_ATTR_FLAG_ALLOCATED) {
+ h[ldb->schema.num_attrib_handlers+i].attr = talloc_strdup(ldb->schema.attrib_handlers,
+ h[ldb->schema.num_attrib_handlers+i].attr);
+ if (h[ldb->schema.num_attrib_handlers+i].attr == NULL) {
+ ldb_oom(ldb);
+ return -1;
+ }
+ }
+ }
ldb->schema.num_attrib_handlers += num_handlers;
return 0;
}
@@ -129,6 +140,9 @@ void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib)
if (h == &ldb_default_attrib_handler) {
return;
}
+ if (h->flags & LDB_ATTR_FLAG_ALLOCATED) {
+ talloc_free(h->attr);
+ }
i = h - ldb->schema.attrib_handlers;
if (i < ldb->schema.num_attrib_handlers - 1) {
memmove(&ldb->schema.attrib_handlers[i],
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index d2f3bd53d3..0af734eb13 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -357,6 +357,9 @@ struct ldb_attrib_handler {
*/
#define LDB_ATTR_FLAG_HIDDEN (1<<0)
+/* the attribute handler name should be freed when released */
+#define LDB_ATTR_FLAG_ALLOCATED (1<<1)
+
/**
The attribute is constructed from other attributes
*/
diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c
index a903ceb4cd..84932ac47f 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c
@@ -71,13 +71,7 @@ static void ltdb_attributes_unload(struct ldb_module *module)
msg = ltdb->cache->attributes;
for (i=0;i<msg->num_elements;i++) {
- const struct ldb_attrib_handler *h;
- /* this is rather ugly - a consequence of const handling */
- h = ldb_attrib_handler(module->ldb, msg->elements[i].name);
ldb_remove_attrib_handler(module->ldb, msg->elements[i].name);
- if (strcmp(h->attr, msg->elements[i].name) == 0) {
- talloc_steal(msg, h->attr);
- }
}
talloc_free(ltdb->cache->attributes);
@@ -163,11 +157,11 @@ static int ltdb_attributes_load(struct ldb_module *module)
goto failed;
}
h2 = *h;
- h2.attr = talloc_strdup(module, msg->elements[i].name);
+ h2.attr = msg->elements[i].name;
+ h2.flags |= LDB_ATTR_FLAG_ALLOCATED;
if (ldb_set_attrib_handlers(module->ldb, &h2, 1) != 0) {
goto failed;
}
- talloc_steal(module->ldb->schema.attrib_handlers, h2.attr);
}
return 0;