param: Simplify get_parametric_helper()
authorVolker Lendecke <vl@samba.org>
Wed, 26 Nov 2014 20:35:27 +0000 (21:35 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 27 Nov 2014 00:41:08 +0000 (01:41 +0100)
With variable sized arrays we don't need talloc_asprintf here

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Nov 27 01:41:09 CET 2014 on sn-devel-104

lib/param/loadparm.c

index 30b11555e3db2d4f7e4837ed4433291333893122..1a60b997b8661c5163ed01ecb60c159dc973f3af 100644 (file)
@@ -241,16 +241,12 @@ struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
                                             const char *type, const char *option,
                                             struct parmlist_entry *global_opts)
 {
-       char* param_key;
+       size_t type_len = strlen(type);
+       size_t option_len = strlen(option);
+       char param_key[type_len + option_len + 2];
        struct parmlist_entry *data = NULL;
-       TALLOC_CTX *mem_ctx = talloc_stackframe();
 
-       param_key = talloc_asprintf(mem_ctx, "%s:%s", type, option);
-       if (param_key == NULL) {
-               DEBUG(0,("asprintf failed!\n"));
-               TALLOC_FREE(mem_ctx);
-               return NULL;
-       }
+       snprintf(param_key, sizeof(param_key), "%s:%s", type, option);
 
        /*
         * Try to fetch the option from the data.
@@ -259,7 +255,6 @@ struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
                data = service->param_opt;
                while (data != NULL) {
                        if (strwicmp(data->key, param_key) == 0) {
-                               TALLOC_FREE(mem_ctx);
                                return data;
                        }
                        data = data->next;
@@ -272,18 +267,12 @@ struct parmlist_entry *get_parametric_helper(struct loadparm_service *service,
        data = global_opts;
        while (data != NULL) {
                if (strwicmp(data->key, param_key) == 0) {
-                       TALLOC_FREE(mem_ctx);
                        return data;
                }
                data = data->next;
        }
 
-
-       TALLOC_FREE(mem_ctx);
-
        return NULL;
-
-
 }
 
 const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,