ini icon indicating copy to clipboard operation
ini copied to clipboard

free(ini->data) crashes on non-standard libc

Open gpetersson opened this issue 3 years ago • 1 comments

Some non-standard libc's (such as on game SDKs or other embedded systems) do not do null checks before freeing memory. I think at least the free(ini->data) line in ini.c should have a check added there so there would not be a crash if a file is not found. Could this be done?

Thanks

gpetersson avatar Sep 16 '21 02:09 gpetersson

As ini_load on success always allocates atleast '\0'1 ini->data could never be NULL. However, what is missing is the check..

  ini->data = malloc(sz + 1);
  if (!ini->data) {
    goto fail;
  }

.. which would make sense to check for consistency as the malloc above2 it is checked as well..

  ini = malloc(sizeof(*ini));
  if (!ini) {
    goto fail;
  }

1 https://github.com/rxi/ini/blob/master/src/ini.c#L200 2 https://github.com/rxi/ini/blob/master/src/ini.c#L182

Wallby avatar Apr 17 '23 09:04 Wallby