ldb: Do not allocate the extended DN name
authorAndrew Bartlett <abartlet@samba.org>
Fri, 17 Jun 2016 01:28:59 +0000 (13:28 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 26 Jun 2016 22:18:17 +0000 (00:18 +0200)
The name must be a hard-coded value from struct ldb_dn_extended_syntax
so just point to that constant pointer

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/common/ldb_dn.c

index ab78776368e5693538316e1b28cfdea17b766cc2..3fa5ab5705600707f2594bea22be8e3c1af6071e 100644 (file)
@@ -54,7 +54,7 @@ struct ldb_dn_component {
 
 struct ldb_dn_ext_component {
 
-       char *name;
+       const char *name;
        struct ldb_val value;
 };
 
@@ -408,11 +408,7 @@ static bool ldb_dn_explode(struct ldb_dn *dn)
                                        goto failed;
                                }
 
-                               dn->ext_components[dn->ext_comp_num].name = talloc_strdup(dn->ext_components, ex_name);
-                               if (!dn->ext_components[dn->ext_comp_num].name) {
-                                       /* ouch */
-                                       goto failed;
-                               }
+                               dn->ext_components[dn->ext_comp_num].name = ext_syntax->name;
                                ret = ext_syntax->read_fn(dn->ldb, dn->ext_components,
                                                          &ex_val, &dn->ext_components[dn->ext_comp_num].value);
                                if (ret != LDB_SUCCESS) {
@@ -1990,12 +1986,14 @@ int ldb_dn_set_extended_component(struct ldb_dn *dn,
        struct ldb_dn_ext_component *p;
        unsigned int i;
        struct ldb_val v2;
-
+       const struct ldb_dn_extended_syntax *ext_syntax;
+       
        if ( ! ldb_dn_validate(dn)) {
                return LDB_ERR_OTHER;
        }
 
-       if (!ldb_dn_extended_syntax_by_name(dn->ldb, name)) {
+       ext_syntax = ldb_dn_extended_syntax_by_name(dn->ldb, name);
+       if (ext_syntax == NULL) {
                /* We don't know how to handle this type of thing */
                return LDB_ERR_INVALID_DN_SYNTAX;
        }
@@ -2006,10 +2004,8 @@ int ldb_dn_set_extended_component(struct ldb_dn *dn,
                                dn->ext_components[i].value =
                                        ldb_val_dup(dn->ext_components, val);
 
-                               dn->ext_components[i].name =
-                                       talloc_strdup(dn->ext_components, name);
-                               if (!dn->ext_components[i].name ||
-                                   !dn->ext_components[i].value.data) {
+                               dn->ext_components[i].name = ext_syntax->name;
+                               if (!dn->ext_components[i].value.data) {
                                        ldb_dn_mark_invalid(dn);
                                        return LDB_ERR_OPERATIONS_ERROR;
                                }
@@ -2170,7 +2166,6 @@ bool ldb_dn_minimise(struct ldb_dn *dn)
         */
 
        for (i = 1; i < dn->ext_comp_num; i++) {
-               LDB_FREE(dn->ext_components[i].name);
                LDB_FREE(dn->ext_components[i].value.data);
        }
        dn->ext_comp_num = 1;