From d3aabf4db176a44d19046b58b99f2edb8c5f49bb Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 28 Dec 2012 22:49:32 -0500 Subject: Fix various small leaks on error cases Spotted by coverity, bug 7816, bugfix on various versions. --- src/common/log.c | 4 +++- src/common/util.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/common') diff --git a/src/common/log.c b/src/common/log.c index 5e2e6b5b50..5f0b4f8d9c 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -833,8 +833,10 @@ add_file_log(const log_severity_list_t *severity, const char *filename) fd = tor_open_cloexec(filename, O_WRONLY|O_CREAT|O_APPEND, 0644); if (fd<0) return -1; - if (tor_fd_seekend(fd)<0) + if (tor_fd_seekend(fd)<0) { + close(fd); return -1; + } LOCK_LOGS(); add_stream_log_impl(severity, filename, fd); diff --git a/src/common/util.c b/src/common/util.c index 6fb597a3a5..29aa83e5d6 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2305,8 +2305,10 @@ read_file_to_str(const char *filename, int flags, struct stat *stat_out) return NULL; } - if ((uint64_t)(statbuf.st_size)+1 >= SIZE_T_CEILING) + if ((uint64_t)(statbuf.st_size)+1 >= SIZE_T_CEILING) { + close(fd); return NULL; + } string = tor_malloc((size_t)(statbuf.st_size+1)); -- cgit v1.2.3-54-g00ecf