Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible run time memory leak with json_load_file API #614

Open
Shobhit-T opened this issue May 22, 2022 · 1 comment
Open

Possible run time memory leak with json_load_file API #614

Shobhit-T opened this issue May 22, 2022 · 1 comment

Comments

@Shobhit-T
Copy link

Hi Team,

I'm seeing some runtime leaks (not visible in valgrind) when parsing a big json file with 10K-20K entries in array.
I'm using the jansson version 2.14.

Sample code:

#include <stdio.h>
#include <unistd.h>
#include <jansson.h>

int main()
{
    json_t *full_file_cfg = NULL;
    json_error_t json_error;
    full_file_cfg = json_load_file("test.json", 0, &json_error);
    if (full_file_cfg != NULL) {
        json_decref(full_file_cfg);
        full_file_cfg = NULL;
    }   
    return 0;
}

The json file looks something like this:

{
  "id": 1,
  "ips": [
    {
      "id": 1,
      "exit_points": [
        {
          "addr_type": "ipv4",
          "address": "1.1.1.1"
        },
        {
          "addr_type": "ipv4",
          "address": "1.1.1.2"
        },
 ...... n entries
        {
          "addr_type": "ipv4",
          "address": "1.1.1.20000"
        }
      ]
    }
  ]
}

When checked with some other memory debugging tools, it reported some leaks as below.

CallStack[23]: may-leak=1000 (56086 bytes)
    expired=1000 (56086 bytes), free_expired=0 (0 bytes)
    alloc=22463 (1258015 bytes), free=0 (0 bytes)
    freed memory live time: min=0 max=0 average=0
    un-freed memory live time: max=10
    0x00007ff767c79020  libc-2.27.so  __libc_malloc()+0
    0x00007ff767fd66c9  libjansson.so
    0x00007ff767fdc219  libjansson.so  json_object_set_new_nocheck()+89
    0x00007ff767fd7cbe  libjansson.so
    0x00007ff767fd7e2e  libjansson.so
    0x00007ff767fd7ca7  libjansson.so
    0x00007ff767fd7e2e  libjansson.so
    0x00007ff767fd7ca7  libjansson.so
    0x00007ff767fd7f56  libjansson.so
    0x00007ff767fd8317  libjansson.so  json_loadf()+183
    0x00007ff767fd84d8  libjansson.so  json_load_file()+72
    0x000055c78e241870  a.out  main()+115

Thanks,

@geoffreycs
Copy link

I know it's been over a year, but any luck with this? I think I'm running into a similar issue in my own project, even though I'm loading the file into a buffer manually before using json_load() on it. My JSON file sucks up about 2.8 GB when parsing, and even though I free the buffer and do a json_decref() (which is working) on the JSON root once I'm done, most of the memory is still unaccounted for and I presume it's being eaten up by the load function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants