]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Make exiting the expand function easier
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 May 2021 14:07:42 +0000 (14:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 May 2021 14:07:42 +0000 (14:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser.c

index 164a25a1bd6e26e1f9a72e58cc373632d04b85a9..e03eca14a6aa0cb7061c72258d634f8b254dc202 100644 (file)
@@ -565,32 +565,28 @@ PAKFIRE_EXPORT char* pakfire_parser_expand(PakfireParser parser,
 
        // Compile all regular expressions
        int r = pakfire_parser_compile_regexes(parser);
-       if (r) {
-               free(buffer);
-               return NULL;
-       }
+       if (r)
+               goto ERROR;
 
        // Expand all variables
        r = pakfire_parser_expand_variables(parser, namespace, &buffer);
-       if (r) {
-               if (buffer)
-                       free(buffer);
-
-               return NULL;
-       }
+       if (r)
+               goto ERROR;
 
        // Expand all commands
        if (parser->flags & PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS) {
                r = pakfire_parser_expand_commands(parser, &buffer);
-               if (r) {
-                       if (buffer)
-                               free(buffer);
-
-                       return NULL;
-               }
+               if (r)
+                       goto ERROR;
        }
 
        return buffer;
+
+ERROR:
+       if (buffer)
+               free(buffer);
+
+       return NULL;
 }
 
 PAKFIRE_EXPORT char* pakfire_parser_get(PakfireParser parser, const char* namespace, const char* name) {