From dfebdcf8a51eec1070cef27ad806d8160f5010b6 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 31 Jan 2025 12:32:30 +0000 Subject: [PATCH] mirrorlist: Don't free the JSON object when checking it's type Signed-off-by: Michael Tremer --- src/pakfire/mirrorlist.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/pakfire/mirrorlist.c b/src/pakfire/mirrorlist.c index fde171da..b1da8bba 100644 --- a/src/pakfire/mirrorlist.c +++ b/src/pakfire/mirrorlist.c @@ -25,6 +25,7 @@ #include #include #include +#include #include 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( -- 2.47.3