Skip to content

Commit

Permalink
Merge pull request #1 from briandowns/open_file_descriptors_bug
Browse files Browse the repository at this point in the history
close file if early return and simply code
  • Loading branch information
briandowns authored Apr 4, 2021
2 parents f96c609 + a97ccc3 commit 43b8e55
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions dot_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,18 @@ env_load(const char *path, const int overwrite)
continue;
}

char *key, *value;
char *token, *string, *tofree;

tofree = string = strdup(line);
key = strsep(&string, SEPERATOR);
value = strsep(&string, NEW_LINE);
char *token = strdup(line);
char *key = strsep(&token, SEPERATOR);
char *value = strsep(&token, NEW_LINE);

replace_double_quotes(value);

if (setenv(key, trim_whitespace(value), overwrite) != 0) {
fclose(f);
return 1;
}

free(token);
}

fclose(f);
free(line);

Expand Down

0 comments on commit 43b8e55

Please sign in to comment.