Fix some more memory leaks 35/15735/1
authorJose Bollo <jose.bollo@iot.bzh>
Wed, 25 Jul 2018 12:13:36 +0000 (14:13 +0200)
committerJose Bollo <jose.bollo@iot.bzh>
Wed, 25 Jul 2018 13:12:48 +0000 (15:12 +0200)
While making coverage test, few leaks appeared.
This corrects the last discorvered ones.

Change-Id: Id9e508bc9412072b628742971b02dd3d62799f3f
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
src/afb-api-v3.c
src/afb-config.c

index 1bda6b0..02853b1 100644 (file)
@@ -239,6 +239,9 @@ void afb_api_v3_unref(struct afb_api_v3 *api)
 {
        if (api && !__atomic_sub_fetch(&api->refcount, 1, __ATOMIC_RELAXED)) {
                afb_export_destroy(api->export);
+               while (api->count)
+                       free(api->verbs[--api->count]);
+               free(api->verbs);
                free(api);
        }
 }
index 3c0d28e..a791969 100644 (file)
@@ -396,30 +396,6 @@ static void printHelp(FILE * file, const char *name)
                name);
 }
 
-/*---------------------------------------------------------
- |   helpers for argument scanning
- +--------------------------------------------------------- */
-
-static const char *current_argument(int optid)
-{
-       if (optarg == 0) {
-               ERROR("option [--%s] needs a value i.e. --%s=xxx",
-                     name_of_optid(optid), name_of_optid(optid));
-               exit(1);
-       }
-       return optarg;
-}
-
-static char *argvalstr(int optid)
-{
-       char *result = strdup(current_argument(optid));
-       if (result == NULL) {
-               ERROR("can't alloc memory");
-               exit(1);
-       }
-       return result;
-}
-
 /**********************************
 * json helpers
 ***********************************/
@@ -584,9 +560,9 @@ static void config_add_optstr(struct json_object *config, int optid)
  |   set the log levels
  +--------------------------------------------------------- */
 
-static void set_log(char *args)
+static void set_log(const char *args)
 {
-       char o = 0, s, *p, *i = args;
+       char o = 0, s, *p, *i = strdupa(args);
        int lvl;
 
        for(;;) switch (*i) {
@@ -653,7 +629,7 @@ static void parse_arguments_inner(int argc, char **argv, struct json_object *con
                        break;
 
                case SET_LOG:
-                       set_log(argvalstr(optid));
+                       set_log(get_arg(optid));
                        break;
 
                case SET_PORT: