diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-09-16 22:34:42 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-09-16 22:34:42 -0400 |
commit | 4ea9fbcdb1feccb3e54ec83b201465252752f046 (patch) | |
tree | 1cd77bec8ce4b2aa507c7f933372b2c7bb3146c3 /src | |
parent | 15b9a1ff10b6892e0cfab3139be765ee0ee6a72c (diff) | |
download | tor-4ea9fbcdb1feccb3e54ec83b201465252752f046.tar.gz tor-4ea9fbcdb1feccb3e54ec83b201465252752f046.zip |
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')
-rw-r--r-- | src/common/sandbox.c | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/src/common/sandbox.c b/src/common/sandbox.c index 33ffd33561..ddfa84b6fe 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; |