]> git.ipfire.org Git - pakfire.git/commitdiff
util: Map JSON strings into memory
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 19:02:28 +0000 (19:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 19:02:28 +0000 (19:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/util.c

index 634c45f0c7293256e2cb2af52628487e6fcaef90..5c3760df51665a44c4a443f3f5e702589437822b 100644 (file)
@@ -451,9 +451,10 @@ static struct json_object* pakfire_json_parse_file(struct pakfire_ctx* ctx, FILE
        struct json_object* json = NULL;
        char* buffer = NULL;
        size_t length = 0;
+       int r;
 
-       // Read everything into memory
-       int r = pakfire_read_file_into_buffer(f, &buffer, &length);
+       // Map everything into memory
+       r = pakfire_mmap(fileno(f), &buffer, &length);
        if (r)
                goto ERROR;
 
@@ -462,7 +463,7 @@ static struct json_object* pakfire_json_parse_file(struct pakfire_ctx* ctx, FILE
 
 ERROR:
        if (buffer)
-               free(buffer);
+               munmap(buffer, length);
 
        return json;
 }