]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
parsers: Statically allocate the namespace
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 14:24:42 +0000 (14:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 14:24:42 +0000 (14:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/parser.c

index 737ad37433c6784e7c07560ceba2110a425cdc1d..31dd8cebebd80226019cfb92e1b7d0752059e914 100644 (file)
@@ -58,7 +58,9 @@ struct pakfire_parser {
 
        struct pakfire_parser* parent;
        int flags;
-       char* namespace;
+
+       // Namespace
+       char namespace[NAME_MAX];
 
        struct pakfire_parser_declaration** declarations;
        size_t num_declarations;
@@ -83,9 +85,6 @@ static void pakfire_parser_free_declarations(struct pakfire_parser* parser) {
 static void pakfire_parser_free(struct pakfire_parser* parser) {
        pakfire_parser_free_declarations(parser);
 
-       if (parser->namespace)
-               free(parser->namespace);
-
        if (parser->parent)
                pakfire_parser_unref(parser->parent);
        if (parser->pakfire)
@@ -996,13 +995,12 @@ const char* pakfire_parser_get_namespace(struct pakfire_parser* parser) {
 }
 
 int pakfire_parser_set_namespace(struct pakfire_parser* parser, const char* namespace) {
-       if (parser->namespace)
-               free(parser->namespace);
+       int r;
 
-       if (namespace)
-               parser->namespace = strdup(namespace);
-       else
-               parser->namespace = NULL;
+       // Store the namespace
+       r = pakfire_string_set(parser->namespace, namespace);
+       if (r < 0)
+               return r;
 
        DEBUG(parser->ctx, "%p: Set namespace to: %s\n", parser, parser->namespace);