aboutsummaryrefslogtreecommitdiff
path: root/src/common/sandbox.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-09-16 22:34:42 -0400
committerNick Mathewson <nickm@torproject.org>2013-09-16 22:34:42 -0400
commit4ea9fbcdb1feccb3e54ec83b201465252752f046 (patch)
tree1cd77bec8ce4b2aa507c7f933372b2c7bb3146c3 /src/common/sandbox.c
parent15b9a1ff10b6892e0cfab3139be765ee0ee6a72c (diff)
downloadtor-4ea9fbcdb1feccb3e54ec83b201465252752f046.tar
tor-4ea9fbcdb1feccb3e54ec83b201465252752f046.tar.gz
Clean up malloc issues in sandbox.c
tor_malloc returns void *; in C, it is not necessary to cast a void* to another pointer type before assigning it. tor_malloc fails with an error rather than returning NULL; it's not necessary to check its output. (In one case, doing so annoyed Coverity.)
Diffstat (limited to 'src/common/sandbox.c')
-rw-r--r--src/common/sandbox.c24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/common/sandbox.c b/src/common/sandbox.c
index 33ffd3356..ddfa84b6f 100644
--- a/src/common/sandbox.c
+++ b/src/common/sandbox.c
@@ -941,15 +941,8 @@ new_element(int syscall, int index, intptr_t value)
{
smp_param_t *param = NULL;
- sandbox_cfg_t *elem = (sandbox_cfg_t*) tor_malloc(sizeof(sandbox_cfg_t));
- if (!elem)
- return NULL;
-
- elem->param = (smp_param_t*) tor_malloc(sizeof(smp_param_t));
- if (!elem->param) {
- tor_free(elem);
- return NULL;
- }
+ sandbox_cfg_t *elem = tor_malloc(sizeof(sandbox_cfg_t));
+ elem->param = tor_malloc(sizeof(smp_param_t));
param = elem->param;
param->syscall = syscall;
@@ -1148,12 +1141,10 @@ sandbox_getaddrinfo(const char *name, const char *servname,
for (el = sb_addr_info; el; el = el->next) {
if (!strcmp(el->name, name)) {
- *res = (struct addrinfo *) tor_malloc(sizeof(struct addrinfo));
- if (!res) {
- return -2;
- }
+ *res = tor_malloc(sizeof(struct addrinfo));
memcpy(*res, el->info, sizeof(struct addrinfo));
+ /* XXXX What if there are multiple items in the list? */
return 0;
}
}
@@ -1183,12 +1174,7 @@ sandbox_add_addrinfo(const char* name)
struct addrinfo hints;
sb_addr_info_t *el = NULL;
- el = (sb_addr_info_t*) tor_malloc(sizeof(sb_addr_info_t));
- if (!el) {
- log_err(LD_BUG,"(Sandbox) failed to allocate addr info!");
- ret = -2;
- goto out;
- }
+ el = tor_malloc(sizeof(sb_addr_info_t));
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;