diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-11-14 20:37:52 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-11-14 20:37:52 -0500 |
commit | 668a6f921551dcacd56b94195552f799cc9e4f8f (patch) | |
tree | b100ecee3c4f91464274c87d3eb223bea6efd298 /reloc.c | |
parent | 0e90fd78a1759af0af31e214aa4c4ba84ffd009d (diff) | |
download | reloc-668a6f921551dcacd56b94195552f799cc9e4f8f.tar.gz |
Plug a few leaks
Diffstat (limited to 'reloc.c')
-rw-r--r-- | reloc.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -2,18 +2,20 @@ RelocMatch *reloc_match(char *haystack, const char *needle) { char *data = haystack; - size_t needle_size = strlen(needle); + char *pattern = strdup(needle); + size_t pattern_size = strlen(pattern); RelocMatch *match = NULL; // Search the needle in the data - if (!(memcmp(data, needle, needle_size))) { - if (!(match = calloc(1, sizeof(RelocMatch)))) { + if (!(memcmp(data, pattern, pattern_size))) { + if (!(match = (RelocMatch *)calloc(1, sizeof(RelocMatch)))) { reloc_error = RELOC_ENOMEM; + free(pattern); return NULL; } size_t data_end = strlen(data); match->begin = data; - match->end = match->begin + needle_size; + match->end = match->begin + pattern_size; match->length = match->end - match->begin; match->post = match->end; match->post_length = strlen(match->post); @@ -21,6 +23,7 @@ RelocMatch *reloc_match(char *haystack, const char *needle) { } reloc_error = RELOC_ESUCCESS; + free(pattern); return match; } @@ -42,14 +45,14 @@ RelocData *reloc_read(const char *filename) { size = ftell(fp); rewind(fp); - if (!(data = calloc(sizeof(char), size + 1))) { + if (!(data = (char *)calloc(size + 1, sizeof(char)))) { reloc_error = RELOC_ENOMEM; return NULL; } // Read data into array fread(data, sizeof(char), size, fp); - if (!(result = (RelocData *)malloc(sizeof(RelocData)))) { + if (!(result = (RelocData *)calloc(1, sizeof(RelocData)))) { reloc_error = RELOC_ENOMEM; return NULL; } @@ -87,6 +90,9 @@ void reloc_deinit_data(RelocData *finfo) { if (finfo->path) { free(finfo->path); } + if (finfo->data) { + free(finfo->data); + } free(finfo); } } |