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

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

Open
gpetersson opened this issue Sep 16, 2021 · 1 comment
Open

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

gpetersson opened this issue Sep 16, 2021 · 1 comment

Comments

@gpetersson
Copy link

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

@Wallby
Copy link

Wallby commented Apr 17, 2023

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

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