mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
Fix various small leaks on error cases
Spotted by coverity, bug 7816, bugfix on various versions.
This commit is contained in:
parent
b509ead20d
commit
d3aabf4db1
3
changes/bug7816_023_small
Normal file
3
changes/bug7816_023_small
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
o Minor bugfixes:
|
||||||
|
- Fix various places where we leak file descriptors or memory on
|
||||||
|
error cases. Spotted by coverity. Fixes parts of bug 7816.
|
@ -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);
|
fd = tor_open_cloexec(filename, O_WRONLY|O_CREAT|O_APPEND, 0644);
|
||||||
if (fd<0)
|
if (fd<0)
|
||||||
return -1;
|
return -1;
|
||||||
if (tor_fd_seekend(fd)<0)
|
if (tor_fd_seekend(fd)<0) {
|
||||||
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
LOCK_LOGS();
|
LOCK_LOGS();
|
||||||
add_stream_log_impl(severity, filename, fd);
|
add_stream_log_impl(severity, filename, fd);
|
||||||
|
@ -2305,8 +2305,10 @@ read_file_to_str(const char *filename, int flags, struct stat *stat_out)
|
|||||||
return NULL;
|
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;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
string = tor_malloc((size_t)(statbuf.st_size+1));
|
string = tor_malloc((size_t)(statbuf.st_size+1));
|
||||||
|
|
||||||
|
@ -992,6 +992,7 @@ connection_listener_new(const struct sockaddr *listensockaddr,
|
|||||||
if (bind(s, listensockaddr, (socklen_t)sizeof(struct sockaddr_un)) == -1) {
|
if (bind(s, listensockaddr, (socklen_t)sizeof(struct sockaddr_un)) == -1) {
|
||||||
log_warn(LD_NET,"Bind to %s failed: %s.", address,
|
log_warn(LD_NET,"Bind to %s failed: %s.", address,
|
||||||
tor_socket_strerror(tor_socket_errno(s)));
|
tor_socket_strerror(tor_socket_errno(s)));
|
||||||
|
tor_close_socket(s);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_PWD_H
|
#ifdef HAVE_PWD_H
|
||||||
@ -1000,9 +1001,11 @@ connection_listener_new(const struct sockaddr *listensockaddr,
|
|||||||
if (pw == NULL) {
|
if (pw == NULL) {
|
||||||
log_warn(LD_NET,"Unable to chown() %s socket: user %s not found.",
|
log_warn(LD_NET,"Unable to chown() %s socket: user %s not found.",
|
||||||
address, options->User);
|
address, options->User);
|
||||||
|
tor_close_socket(s);
|
||||||
} else if (chown(address, pw->pw_uid, pw->pw_gid) < 0) {
|
} else if (chown(address, pw->pw_uid, pw->pw_gid) < 0) {
|
||||||
log_warn(LD_NET,"Unable to chown() %s socket: %s.",
|
log_warn(LD_NET,"Unable to chown() %s socket: %s.",
|
||||||
address, strerror(errno));
|
address, strerror(errno));
|
||||||
|
tor_close_socket(s);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1316,8 +1316,11 @@ load_bridge_stats(time_t now)
|
|||||||
|
|
||||||
fname = get_datadir_fname2("stats", "bridge-stats");
|
fname = get_datadir_fname2("stats", "bridge-stats");
|
||||||
contents = read_file_to_str(fname, RFTS_IGNORE_MISSING, NULL);
|
contents = read_file_to_str(fname, RFTS_IGNORE_MISSING, NULL);
|
||||||
if (contents && validate_bridge_stats(contents, now))
|
if (contents && validate_bridge_stats(contents, now)) {
|
||||||
bridge_stats_extrainfo = contents;
|
bridge_stats_extrainfo = contents;
|
||||||
|
} else {
|
||||||
|
tor_free(contents);
|
||||||
|
}
|
||||||
|
|
||||||
tor_free(fname);
|
tor_free(fname);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user