diff options
author | graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2009-11-03 22:14:39 (EST) |
---|---|---|
committer | graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2009-11-03 22:14:39 (EST) |
commit | edf1b1964b565726a0b0f730b109e4491c7929b9 (patch) | |
tree | 1b44b552451f0dd57c7da2b547e79c9df6943348 /libopkg/file_util.c | |
parent | 923f73d334e7969a814d09cbba3a2a416ac7b0dc (diff) |
Remove some strdup abuse.
git-svn-id: http://opkg.googlecode.com/svn/trunk@254 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg/file_util.c')
-rw-r--r-- | libopkg/file_util.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/libopkg/file_util.c b/libopkg/file_util.c index 4176257..b867df7 100644 --- a/libopkg/file_util.c +++ b/libopkg/file_util.c @@ -83,7 +83,7 @@ char *file_read_line_alloc(FILE *file) strcat(line, buf); } else { line_size = buf_len + 1; - line = strdup(buf); + line = xstrdup(buf); } if (buf[buf_len - 1] == '\n') { break; @@ -150,21 +150,24 @@ char *file_md5sum_alloc(const char *file_name) md5sum_hex = calloc(1, md5sum_hex_len + 1); if (md5sum_hex == NULL) { fprintf(stderr, "%s: out of memory\n", __FUNCTION__); - return strdup(""); + return NULL; } file = fopen(file_name, "r"); if (file == NULL) { fprintf(stderr, "%s: Failed to open file %s: %s\n", __FUNCTION__, file_name, strerror(errno)); - return strdup(""); + free(md5sum_hex); + return NULL; } err = md5_stream(file, md5sum_bin); if (err) { fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n", __FUNCTION__, file_name, strerror(err)); - return strdup(""); + fclose(file); + free(md5sum_hex); + return NULL; } fclose(file); @@ -200,21 +203,24 @@ char *file_sha256sum_alloc(const char *file_name) sha256sum_hex = calloc(1, sha256sum_hex_len + 1); if (sha256sum_hex == NULL) { fprintf(stderr, "%s: out of memory\n", __FUNCTION__); - return strdup(""); + return NULL; } file = fopen(file_name, "r"); if (file == NULL) { fprintf(stderr, "%s: Failed to open file %s: %s\n", __FUNCTION__, file_name, strerror(errno)); - return strdup(""); + free(sha256sum_hex); + return NULL; } err = sha256_stream(file, sha256sum_bin); if (err) { fprintf(stderr, "%s: ERROR computing sha256sum for %s: %s\n", __FUNCTION__, file_name, strerror(err)); - return strdup(""); + fclose(file); + free(sha256sum_hex); + return NULL; } fclose(file); |