lib/util: Avoid a talloc in ms_fnmatch_protocol
authorVolker Lendecke <vl@samba.org>
Tue, 25 Oct 2016 10:46:00 +0000 (12:46 +0200)
committerRalph Boehme <slow@samba.org>
Sun, 22 Jan 2017 17:30:12 +0000 (18:30 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/util/ms_fnmatch.c

index 7f1cce06bb1eb7a93fd79dda28d8629fa280a286..c0f61ab04e75da6880918d21d5aab82fe5b82589 100644 (file)
@@ -165,7 +165,6 @@ int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol,
                        bool is_case_sensitive)
 {
        int ret, count, i;
-       struct max_n *max_n = NULL;
 
        if (strcmp(string, "..") == 0) {
                string = ".";
@@ -210,15 +209,14 @@ int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol,
                if (pattern[i] == '*' || pattern[i] == '<') count++;
        }
 
-       max_n = talloc_zero_array(NULL, struct max_n, count);
-       if (max_n == NULL) {
-               return -1;
-       }
+       {
+               struct max_n max_n[count];
 
-       ret = ms_fnmatch_core(pattern, string, max_n, strrchr(string, '.'),
-                             is_case_sensitive);
+               memset(max_n, 0, sizeof(struct max_n) * count);
 
-       talloc_free(max_n);
+               ret = ms_fnmatch_core(pattern, string, max_n, strrchr(string, '.'),
+                                     is_case_sensitive);
+       }
 
        return ret;
 }