diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-12-29 01:35:09 -0500 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-12-29 01:35:09 -0500 |
| commit | 4595ada2f69b42670c85a63c7d2344af63f2afe7 (patch) | |
| tree | 0d528d8177aceefcf74fb7306fc0fc7cc3c41ece /src/find.c | |
| parent | 8ae4f8f5985445b1ce3547975f407847c0fee0f7 (diff) | |
| download | spmc-4595ada2f69b42670c85a63c7d2344af63f2afe7.tar.gz | |
Minor fixes:
* size_t in place of int
* Moved some variables closer to their execution scope
* Add some error checks
Diffstat (limited to 'src/find.c')
| -rw-r--r-- | src/find.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -39,6 +39,7 @@ char *find_file(const char *root, const char *filename) { } if (!(rootpath = realpath(root, NULL))) { + free(path); return NULL; } @@ -103,11 +104,13 @@ int find_in_file(const char *filename, const char *pattern) { } long int file_len = get_file_size(filename); - if (file_len < 0) { + if (file_len == -1) { + fclose(fp); return -1; } char *buffer = (char *)calloc((size_t) file_len, sizeof(char)); if (!buffer) { + fclose(fp); return -1; } size_t pattern_len = strlen(pattern); |
