r8084: do not leak memory on errors
authorSimo Sorce <idra@samba.org>
Sat, 2 Jul 2005 18:43:22 +0000 (18:43 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:19:07 +0000 (13:19 -0500)
(This used to be commit 2e328e6c2fc2c66b0d0de910cd43ab232049bc90)

source4/lib/ldb/common/ldb_dn.c
source4/lib/ldb/ldb_tdb/ldb_tdb.c

index 8b9cf4e1297d9b0f0da3e001e1cd67b95b33273b..7556a144e2cabeccacfbeaa0bdcd8fd07bea629b 100644 (file)
@@ -37,7 +37,7 @@
 #include "includes.h"
 #include "ldb/include/ldb.h"
 #include "ldb/include/ldb_private.h"
-
+#include <ctype.h>
 
 #define LDB_DN_NULL_FAILED(x) if (!(x)) goto failed
 
index eb72e665f5acb625a0e2be12d6cbf316ce109fe1..df94b0691d21855d5cdc37539b5e94be52f3dc70 100644 (file)
@@ -56,6 +56,8 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn)
        TDB_DATA key;
        char *key_str = NULL;
        char *dn_folded = NULL;
+       struct ldb_dn *edn = NULL;
+       struct ldb_dn *cedn = NULL;
 
        /*
          most DNs are case insensitive. The exception is index DNs for
@@ -71,8 +73,6 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn)
        if (*dn == '@') {
                dn_folded = talloc_strdup(ldb, dn);
        } else {
-               struct ldb_dn *edn, *cedn;
-
                edn = ldb_dn_explode(ldb, dn);
                if (!edn)
                        goto failed;
@@ -89,10 +89,6 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn)
                talloc_free(cedn);
        }
 
-       if (!dn_folded) {
-               goto failed;
-       }
-
        key_str = talloc_asprintf(ldb, "DN=%s", dn_folded);
        talloc_free(dn_folded);
 
@@ -101,11 +97,13 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn)
        }
 
        key.dptr = key_str;
-       key.dsize = strlen(key_str)+1;
+       key.dsize = strlen(key_str) + 1;
 
        return key;
 
 failed:
+       talloc_free(edn);
+       talloc_free(cedn);
        errno = ENOMEM;
        key.dptr = NULL;
        key.dsize = 0;