Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ts_config: fix conf file's string memory management
we can't free getenv's memory region. we should however free whatever
strdup returns.
  • Loading branch information
merge committed Dec 5, 2016
1 parent c57c889 commit 3217f3c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/ts_config.c
Expand Up @@ -43,16 +43,24 @@ int ts_config(struct tsdev *ts)
FILE *f;
int line = 0;
int ret = 0;
short strdup_allocated = 0;

char *conffile;

if( (conffile = getenv("TSLIB_CONFFILE")) == NULL) {
conffile = strdup (TS_CONF);
if (conffile) {
strdup_allocated = 1;
} else {
perror("Couldn't find tslib config file");
return -1;
}
}

f = fopen(conffile, "r");
if (!f) {
free(conffile);
if (strdup_allocated)
free(conffile);

perror("Couldnt open tslib config file");
return -1;
Expand Down Expand Up @@ -113,7 +121,9 @@ int ts_config(struct tsdev *ts)
}

fclose(f);
free(conffile);

if (strdup_allocated)
free(conffile);

return ret;
}
Expand Down

0 comments on commit 3217f3c

Please sign in to comment.