]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: parser: Return the declarations parser
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 Mar 2019 10:34:53 +0000 (10:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 Mar 2019 10:34:53 +0000 (10:34 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c
src/libpakfire/include/pakfire/parser.h
src/libpakfire/parser/grammar.y

index d7836bc88348dabdf9eef0fd8cf6f27ec4ccfcaa..405cd1969a7c6d3234117dcba40045cb54337807 100644 (file)
@@ -359,11 +359,16 @@ static int pakfire_archive_parse_entry_metadata(PakfireArchive archive,
        }
 
        // Parse metadata file
-       r = pakfire_parser_parse_metadata(archive->pakfire, (const char*)data, data_size);
+       struct pakfire_parser_declaration** declarations = \
+               pakfire_parser_parse_metadata(archive->pakfire, (const char*)data, data_size);
 
        pakfire_free(data);
 
-       return r;
+       // Error when nothing was returned
+       if (!declarations)
+               return 1;
+
+       return 0;
 }
 
 static int pakfire_archive_parse_entry_filelist(PakfireArchive archive,
index 300c9e6820a7cad1f2928c42a0b4e46ff23930fe..f08da6b242e3def108ce1a9eee6b9cb7a2cf51d3 100644 (file)
@@ -30,7 +30,8 @@ struct pakfire_parser_declaration {
        char* value;
 };
 
-int pakfire_parser_parse_metadata(Pakfire pakfire, const char* data, size_t len);
+struct pakfire_parser_declaration** pakfire_parser_parse_metadata(Pakfire pakfire,
+       const char* data, size_t len);
 
 #endif /* PAKFIRE_PRIVATE */
 
index 5ad926707d118f35709d148e1ea74787bb7198dc..d9c4aae96fe06de60055c888d57b1c89ec15f9e9 100644 (file)
@@ -216,7 +216,7 @@ static int pakfire_parser_add_declaration(Pakfire pakfire,
        return 0;
 }
 
-int pakfire_parser_parse_metadata(Pakfire pakfire, const char* data, size_t len) {
+struct pakfire_parser_declaration** pakfire_parser_parse_metadata(Pakfire pakfire, const char* data, size_t len) {
        DEBUG(pakfire, "Parsing the following data:\n%s\n", data);
 
        num_lines = 1;
@@ -229,7 +229,20 @@ int pakfire_parser_parse_metadata(Pakfire pakfire, const char* data, size_t len)
        int r = yyparse(pakfire, declarations);
        yy_delete_buffer(buffer);
 
-       return r;
+       // Cleanup declarations in case of an error
+       if (r) {
+               for (unsigned int i = 0; i < NUM_DECLARATIONS; i++) {
+                       if (declarations[i])
+                               pakfire_free(declarations[i]);
+               }
+
+               pakfire_free(declarations);
+
+               // Return nothing
+               return NULL;
+       }
+
+       return declarations;
 }
 
 void yyerror(Pakfire pakfire, struct pakfire_parser_declaration** declarations, const char* s) {