]> granicus.if.org Git - strace/commitdiff
filter_qualify: move memory allocation from parse_inject_expression
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 14 Jan 2018 00:43:12 +0000 (00:43 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 15 Jan 2018 16:23:54 +0000 (16:23 +0000)
* filter_qualify.c (parse_inject_expression): Replace "s" and "buf"
arguments with "str" argument, use it instead of "s" and "*buf".
(qualify_inject_common): Rename "buf" to "copy", initialize it to a copy
of "str", pass "copy" to parse_inject_expression instead of "str" and
"buf".

filter_qualify.c

index 5b0ef28cb627f1c15266c577fc9a8b7b4b4f82b8..1bfcd86b8c98857ba2395bfba814f390a6535c00 100644 (file)
@@ -155,7 +155,7 @@ parse_inject_token(const char *const token, struct inject_opts *const fopts,
 }
 
 static char *
-parse_inject_expression(const char *const s, char **buf,
+parse_inject_expression(char *const str,
                        struct inject_opts *const fopts,
                        const bool fault_tokens_only)
 {
@@ -163,21 +163,15 @@ parse_inject_expression(const char *const s, char **buf,
        char *name = NULL;
        char *token;
 
-       *buf = xstrdup(s);
-       for (token = strtok_r(*buf, ":", &saveptr); token;
+       for (token = strtok_r(str, ":", &saveptr); token;
             token = strtok_r(NULL, ":", &saveptr)) {
                if (!name)
                        name = token;
                else if (!parse_inject_token(token, fopts, fault_tokens_only))
-                       goto parse_error;
+                       return NULL;
        }
 
-       if (name)
-               return name;
-
-parse_error:
-       free(*buf);
-       return *buf = NULL;
+       return name;
 }
 
 static void
@@ -245,8 +239,8 @@ qualify_inject_common(const char *const str,
                .first = 1,
                .step = 1
        };
-       char *buf = NULL;
-       char *name = parse_inject_expression(str, &buf, &opts, fault_tokens_only);
+       char *copy = xstrdup(str);
+       char *name = parse_inject_expression(copy, &opts, fault_tokens_only);
        if (!name) {
                error_msg_and_die("invalid %s '%s'", description, str);
        }
@@ -267,7 +261,7 @@ qualify_inject_common(const char *const str,
                alloc_number_set_array(SUPPORTED_PERSONALITIES);
        qualify_syscall_tokens(name, tmp_set, description);
 
-       free(buf);
+       free(copy);
 
        /*
         * Initialize inject_vec accourding to tmp_set.