use the tor_malloc_zero wrapper

svn:r837
This commit is contained in:
Roger Dingledine 2003-11-18 08:20:19 +00:00
parent ec02f83f94
commit ac56486bf6
7 changed files with 13 additions and 21 deletions

View File

@ -58,8 +58,7 @@ void circuit_remove(circuit_t *circ) {
circuit_t *circuit_new(circ_id_t p_circ_id, connection_t *p_conn) { circuit_t *circuit_new(circ_id_t p_circ_id, connection_t *p_conn) {
circuit_t *circ; circuit_t *circ;
circ = (circuit_t *)tor_malloc(sizeof(circuit_t)); circ = tor_malloc_zero(sizeof(circuit_t));
memset(circ,0,sizeof(circuit_t)); /* zero it out */
circ->timestamp_created = time(NULL); circ->timestamp_created = time(NULL);

View File

@ -76,8 +76,7 @@ connection_t *connection_new(int type) {
connection_t *conn; connection_t *conn;
time_t now = time(NULL); time_t now = time(NULL);
conn = (connection_t *)tor_malloc(sizeof(connection_t)); conn = tor_malloc_zero(sizeof(connection_t));
memset(conn,0,sizeof(connection_t)); /* zero it out to start */
conn->s = -1; /* give it a default of 'not used' */ conn->s = -1; /* give it a default of 'not used' */
conn->type = type; conn->type = type;
@ -86,8 +85,7 @@ connection_t *connection_new(int type) {
conn->outbuf = buf_new(); conn->outbuf = buf_new();
} }
if (type == CONN_TYPE_AP) { if (type == CONN_TYPE_AP) {
conn->socks_request = tor_malloc(sizeof(socks_request_t)); conn->socks_request = tor_malloc_zero(sizeof(socks_request_t));
memset(conn->socks_request, 0, sizeof(socks_request_t));
} }
conn->timestamp_created = now; conn->timestamp_created = now;
@ -264,7 +262,7 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_
} }
set_socket_nonblocking(s); set_socket_nonblocking(s);
memset((void *)&dest_addr,0,sizeof(dest_addr)); memset(&dest_addr,0,sizeof(dest_addr));
dest_addr.sin_family = AF_INET; dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(port); dest_addr.sin_port = htons(port);
dest_addr.sin_addr.s_addr = htonl(addr); dest_addr.sin_addr.s_addr = htonl(addr);

View File

@ -672,7 +672,8 @@ static int connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
buf[1] = success ? SOCKS5_SUCCESS : SOCKS5_GENERIC_ERROR; buf[1] = success ? SOCKS5_SUCCESS : SOCKS5_GENERIC_ERROR;
buf[2] = 0; buf[2] = 0;
buf[3] = 1; /* ipv4 addr */ buf[3] = 1; /* ipv4 addr */
memset(buf+4,0,6); /* XXX set external addr/port to 0, see what breaks */ memset(buf+4,0,6); /* Set external addr/port to 0.
The spec doesn't seem to say what to do here. -RD */
connection_write_to_buf(buf,10,conn); connection_write_to_buf(buf,10,conn);
return flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen); /* try to flush it */ return flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen); /* try to flush it */
} }

View File

@ -340,9 +340,8 @@ list_running_servers(char **nicknames_out)
for (i = 0; i<n; ++i) { for (i = 0; i<n; ++i) {
length += strlen(nickname_lst[i]); length += strlen(nickname_lst[i]);
} }
*nicknames_out = tor_malloc(length); *nicknames_out = tor_malloc_zero(length);
cp = *nicknames_out; cp = *nicknames_out;
memset(cp,0,length);
for (i = 0; i<n; ++i) { for (i = 0; i<n; ++i) {
if (i) if (i)
strcat(cp, " "); strcat(cp, " ");

View File

@ -127,8 +127,7 @@ int dns_resolve(connection_t *exitconn) {
return -1; return -1;
} }
} else { /* need to add it */ } else { /* need to add it */
resolve = tor_malloc(sizeof(struct cached_resolve)); resolve = tor_malloc_zero(sizeof(struct cached_resolve));
memset(resolve, 0, sizeof(struct cached_resolve));
resolve->state = CACHE_STATE_PENDING; resolve->state = CACHE_STATE_PENDING;
resolve->expire = now + 15*60; /* 15 minutes */ resolve->expire = now + 15*60; /* 15 minutes */
strncpy(resolve->question, exitconn->address, MAX_ADDRESSLEN); strncpy(resolve->question, exitconn->address, MAX_ADDRESSLEN);

View File

@ -34,8 +34,7 @@ static int ol_length=0;
int onion_pending_add(circuit_t *circ) { int onion_pending_add(circuit_t *circ) {
struct onion_queue_t *tmp; struct onion_queue_t *tmp;
tmp = tor_malloc(sizeof(struct onion_queue_t)); tmp = tor_malloc_zero(sizeof(struct onion_queue_t));
memset(tmp, 0, sizeof(struct onion_queue_t));
tmp->circ = circ; tmp->circ = circ;
if(!ol_tail) { if(!ol_tail) {
@ -460,8 +459,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout
} }
/* Okay, so we haven't used 'choice' before. */ /* Okay, so we haven't used 'choice' before. */
hop = (crypt_path_t *)tor_malloc(sizeof(crypt_path_t)); hop = (crypt_path_t *)tor_malloc_zero(sizeof(crypt_path_t));
memset(hop, 0, sizeof(crypt_path_t));
/* link hop into the cpath, at the end. */ /* link hop into the cpath, at the end. */
if (*head_ptr) { if (*head_ptr) {

View File

@ -763,8 +763,7 @@ routerinfo_t *router_get_entry_from_string(char**s) {
return NULL; return NULL;
} }
router = tor_malloc(sizeof(routerinfo_t)); router = tor_malloc_zero(sizeof(routerinfo_t));
memset(router,0,sizeof(routerinfo_t)); /* zero it out first */
router->onion_pkey = router->identity_pkey = router->link_pkey = NULL; router->onion_pkey = router->identity_pkey = router->link_pkey = NULL;
if (tok->val.cmd.n_args != 6) { if (tok->val.cmd.n_args != 6) {
@ -970,8 +969,7 @@ static int router_add_exit_policy(routerinfo_t *router,
return -1; return -1;
arg = tok->val.cmd.args[0]; arg = tok->val.cmd.args[0];
newe = tor_malloc(sizeof(struct exit_policy_t)); newe = tor_malloc_zero(sizeof(struct exit_policy_t));
memset(newe,0,sizeof(struct exit_policy_t));
newe->string = tor_malloc(8+strlen(arg)); newe->string = tor_malloc(8+strlen(arg));
if (tok->tp == K_REJECT) { if (tok->tp == K_REJECT) {