diff options
author | Oleh Kravchenko <oleg@kaa.org.ua> | 2019-04-14 21:21:04 +0300 |
---|---|---|
committer | Oleh Kravchenko <oleg@kaa.org.ua> | 2019-04-14 21:31:44 +0300 |
commit | 78c72432893a958597dea71758af063b9395c308 (patch) | |
tree | a48354cf6eaa2ca1153c55891d860cf859ea468b /src/stringmap.c | |
parent | 137a44fd78e11fd35749712f39b0e985deee4fb8 (diff) | |
download | distcc-git-78c72432893a958597dea71758af063b9395c308.tar.gz |
Fix memory leaks detected by PVS-Studio
- climasq.c:121 The function was exited without releasing the 'buf' pointer.
- argutil.c:109 The function was exited without releasing the 'b' pointer.
- stringmap.c:53 The function was exited without releasing the 'result' pointer.
- util.c:596 when realloc() fails in allocating memory,
original pointer 'loc' is lost.
Signed-off-by: Oleh Kravchenko <oleg@kaa.org.ua>
Diffstat (limited to 'src/stringmap.c')
-rw-r--r-- | src/stringmap.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/stringmap.c b/src/stringmap.c index 2fa2a59..483e86a 100644 --- a/src/stringmap.c +++ b/src/stringmap.c @@ -43,14 +43,20 @@ */ stringmap_t *stringmap_load(const char *filename, int numFinalWordsToMatch) { - stringmap_t *result = calloc(1, sizeof(*result)); - FILE *fp = fopen(filename, "r"); + stringmap_t *result; + FILE *fp; char buf[2*PATH_MAX]; int n; + result = calloc(1, sizeof(*result)); + if (!result) + return NULL; result->numFinalWordsToMatch = numFinalWordsToMatch; - if (!fp) + fp = fopen(filename, "r"); + if (!fp) { + free(result); return NULL; + } n=0; while (fgets(buf, sizeof(buf), fp)) n++; |