Skip to content

Commit

Permalink
Fix uninitialized field issues in ini_example.c
Browse files Browse the repository at this point in the history
  • Loading branch information
benhoyt committed Apr 22, 2021
1 parent 0b9092e commit 4f251f0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions examples/ini_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ static int handler(void* user, const char* section, const char* name,
int main(int argc, char* argv[])
{
configuration config;
config.version = 0; /* set defaults */
config.name = NULL;
config.email = NULL;

if (ini_parse("test.ini", handler, &config) < 0) {
printf("Can't load 'test.ini'\n");
Expand All @@ -41,8 +44,10 @@ int main(int argc, char* argv[])
printf("Config loaded from 'test.ini': version=%d, name=%s, email=%s\n",
config.version, config.name, config.email);

free((void*)config.name);
free((void*)config.email);
if (config.name)
free((void*)config.name);
if (config.email)
free((void*)config.email);

return 0;
}

0 comments on commit 4f251f0

Please sign in to comment.