]> git.ipfire.org Git - pakfire.git/commitdiff
config: Don't copy section names
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 Sep 2023 17:18:40 +0000 (17:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 Sep 2023 17:18:40 +0000 (17:18 +0000)
This mainly makes the static analyzer happy :)

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/config.c
src/libpakfire/include/pakfire/config.h
src/libpakfire/repo.c

index 327b2605f33c6d7afa6b0906941e014802a36efe..5dd8c266c2811eed81f47cedb92b9ce2c61065c1 100644 (file)
@@ -305,11 +305,11 @@ FILE* pakfire_config_get_fopen(struct pakfire_config* config,
        return NULL;
 }
 
-static int pakfire_section_in_sections(char** sections, const char* section) {
+static int pakfire_section_in_sections(const char** sections, const char* section) {
        if (!sections)
                return 0;
 
-       for (char** s = sections; *s; s++) {
+       for (const char** s = sections; *s; s++) {
                if (strcmp(section, *s) == 0)
                        return 1;
        }
@@ -317,10 +317,10 @@ static int pakfire_section_in_sections(char** sections, const char* section) {
        return 0;
 }
 
-char** pakfire_config_sections(struct pakfire_config* config) {
+const char** pakfire_config_sections(struct pakfire_config* config) {
        struct pakfire_config_entry* entry = NULL;
 
-       char** sections = NULL;
+       const char** sections = NULL;
        size_t num_sections = 0;
 
        STAILQ_FOREACH(entry, &config->entries, nodes) {
@@ -337,7 +337,7 @@ char** pakfire_config_sections(struct pakfire_config* config) {
                if (!sections)
                        return NULL;
 
-               sections[num_sections - 1] = strdup(entry->section);
+               sections[num_sections - 1] = entry->section;
 
                // Terminate the array
                sections[num_sections] = NULL;
@@ -572,7 +572,7 @@ int pakfire_config_dump(struct pakfire_config* config, FILE* f) {
        int r;
 
        // Fetch a list of all available sections
-       char** sections = pakfire_config_sections(config);
+       const char** sections = pakfire_config_sections(config);
 
        // Dump the default section
        r = pakfire_config_dump_section(config, "", f);
@@ -581,7 +581,7 @@ int pakfire_config_dump(struct pakfire_config* config, FILE* f) {
 
        // Dump all sections
        if (sections) {
-               for (char** section = sections; *section; section++) {
+               for (const char** section = sections; *section; section++) {
                        r = pakfire_config_dump_section(config, *section, f);
                        if (r)
                                goto ERROR;
@@ -589,11 +589,8 @@ int pakfire_config_dump(struct pakfire_config* config, FILE* f) {
        }
 
 ERROR:
-       if (sections) {
-               for (char** section = sections; *section; section++)
-                       free(*section);
+       if (sections)
                free(sections);
-       }
 
        return r;
 }
index 81534377b6a261e0495dc66edce36a773d4e4501..9fca5c8f8cb33a65e46c3b17dfe7951cf19c6cd6 100644 (file)
@@ -47,7 +47,7 @@ size_t pakfire_config_get_bytes(struct pakfire_config* config,
 FILE* pakfire_config_get_fopen(struct pakfire_config* config,
        const char* section, const char* key);
 
-char** pakfire_config_sections(struct pakfire_config* config);
+const char** pakfire_config_sections(struct pakfire_config* config);
 int pakfire_config_has_section(struct pakfire_config* config, const char* section);
 
 int pakfire_config_read(struct pakfire_config* config, FILE* f);
index e2e80d63a5c9d4194206a3477f3b250facf89aec..a9f0e3d960bcc18b163e9258cb571d5267dcfa26 100644 (file)
@@ -208,7 +208,7 @@ ERROR:
 }
 
 int pakfire_repo_import(struct pakfire* pakfire, struct pakfire_config* config) {
-       char** sections = pakfire_config_sections(config);
+       const char** sections = pakfire_config_sections(config);
 
        // The configuration seems to be empty
        if (!sections)
@@ -284,9 +284,8 @@ int pakfire_repo_import(struct pakfire* pakfire, struct pakfire_config* config)
                goto ERROR;
 
 ERROR:
-       for (char** section = sections; *section; section++)
-               free(*section);
-       free(sections);
+       if (sections)
+               free(sections);
 
        return r;
 }