]> git.ipfire.org Git - pakfire.git/commitdiff
mirrorlist: Don't free the JSON object when checking it's type
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 Jan 2025 12:32:30 +0000 (12:32 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 Jan 2025 12:32:30 +0000 (12:32 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/mirrorlist.c

index fde171da7923c6a4e97c96c71d95948e34a4fb94..b1da8bbaef0d2be136d66bee74a814e30d8649f1 100644 (file)
@@ -25,6 +25,7 @@
 #include <pakfire/logging.h>
 #include <pakfire/mirror.h>
 #include <pakfire/mirrorlist.h>
+#include <pakfire/string.h>
 #include <pakfire/util.h>
 
 struct pakfire_mirrorlist {
@@ -93,33 +94,26 @@ struct pakfire_mirrorlist* pakfire_mirrorlist_unref(struct pakfire_mirrorlist* l
 static int pakfire_mirrorlist_check_mirrorlist(struct pakfire_mirrorlist* list,
                struct json_object* root) {
        struct json_object* typeobj = NULL;
-       int r = 1;
+       int r;
 
        r = json_object_object_get_ex(root, "type", &typeobj);
        if (!r) {
                ERROR(list->ctx, "mirrorlist does not have a 'type' attribute\n");
-               goto ERROR;
+               return -EBADMSG;
        }
 
        const char* type = json_object_get_string(typeobj);
        if (!type) {
                ERROR(list->ctx, "mirrorlist has an empty or unknown 'type' attribute\n");
-               goto ERROR;
+               return -EBADMSG;
        }
 
-       if (strcmp(type, "mirrorlist") != 0) {
+       if (!pakfire_string_equals(type, "mirrorlist")) {
                ERROR(list->ctx, "Unexpected type: %s\n", type);
-               goto ERROR;
+               return -EBADMSG;
        }
 
-       // Success
-       r = 0;
-
-ERROR:
-       if (typeobj)
-               json_object_put(typeobj);
-
-       return r;
+       return 0;
 }
 
 static int pakfire_mirrorlist_add_mirror_from_url(