}
// 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,
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 */
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;
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) {