Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Alexander Færøy
tor
Commits
d52ceaa3
Commit
d52ceaa3
authored
Jan 31, 2018
by
Alexander Færøy
Browse files
Apply alloc-type-info.cocci
parent
ace239d5
Pipeline
#16854392
failed with stage
in 8 minutes and 43 seconds
Changes
126
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
75 changed files
with
529 additions
and
268 deletions
+529
-268
src/common/address.c
src/common/address.c
+2
-1
src/common/aes.c
src/common/aes.c
+2
-1
src/common/buffers.c
src/common/buffers.c
+1
-1
src/common/compat.c
src/common/compat.c
+11
-7
src/common/compat_libevent.c
src/common/compat_libevent.c
+2
-1
src/common/compat_pthreads.c
src/common/compat_pthreads.c
+2
-1
src/common/compat_threads.c
src/common/compat_threads.c
+6
-3
src/common/compress.c
src/common/compress.c
+2
-1
src/common/compress_lzma.c
src/common/compress_lzma.c
+2
-1
src/common/compress_zlib.c
src/common/compress_zlib.c
+2
-1
src/common/compress_zstd.c
src/common/compress_zstd.c
+2
-1
src/common/confline.c
src/common/confline.c
+6
-3
src/common/container.c
src/common/container.c
+2
-1
src/common/crypto.c
src/common/crypto.c
+6
-4
src/common/crypto_openssl_mgt.c
src/common/crypto_openssl_mgt.c
+2
-1
src/common/di_ops.c
src/common/di_ops.c
+2
-1
src/common/log.c
src/common/log.c
+8
-6
src/common/memarea.c
src/common/memarea.c
+4
-2
src/common/procmon.c
src/common/procmon.c
+2
-2
src/common/sandbox.c
src/common/sandbox.c
+4
-2
src/common/storagedir.c
src/common/storagedir.c
+5
-2
src/common/timers.c
src/common/timers.c
+2
-1
src/common/tortls.c
src/common/tortls.c
+4
-2
src/common/util.c
src/common/util.c
+35
-5
src/common/util.h
src/common/util.h
+10
-0
src/common/workqueue.c
src/common/workqueue.c
+8
-5
src/or/addressmap.c
src/or/addressmap.c
+6
-3
src/or/bridges.c
src/or/bridges.c
+2
-1
src/or/channel.c
src/or/channel.c
+2
-1
src/or/circuitbuild.c
src/or/circuitbuild.c
+12
-6
src/or/circuitlist.c
src/or/circuitlist.c
+8
-4
src/or/circuitstats.c
src/or/circuitstats.c
+12
-6
src/or/command.c
src/or/command.c
+2
-1
src/or/config.c
src/or/config.c
+25
-14
src/or/confparse.c
src/or/confparse.c
+5
-3
src/or/connection.c
src/or/connection.c
+20
-10
src/or/connection_edge.c
src/or/connection_edge.c
+2
-1
src/or/connection_or.c
src/or/connection_or.c
+4
-2
src/or/conscache.c
src/or/conscache.c
+6
-3
src/or/consdiff.c
src/or/consdiff.c
+2
-1
src/or/consdiffmgr.c
src/or/consdiffmgr.c
+1
-1
src/or/control.c
src/or/control.c
+7
-4
src/or/cpuworker.c
src/or/cpuworker.c
+4
-2
src/or/dircollate.c
src/or/dircollate.c
+4
-2
src/or/dirserv.c
src/or/dirserv.c
+28
-14
src/or/dirvote.c
src/or/dirvote.c
+52
-29
src/or/dns.c
src/or/dns.c
+1
-1
src/or/entrynodes.c
src/or/entrynodes.c
+10
-5
src/or/fp_pair.c
src/or/fp_pair.c
+4
-2
src/or/geoip.c
src/or/geoip.c
+12
-7
src/or/hs_cache.c
src/or/hs_cache.c
+4
-2
src/or/hs_circuit.c
src/or/hs_circuit.c
+2
-1
src/or/hs_circuitmap.c
src/or/hs_circuitmap.c
+4
-2
src/or/hs_common.c
src/or/hs_common.c
+2
-1
src/or/hs_descriptor.c
src/or/hs_descriptor.c
+2
-1
src/or/hs_service.c
src/or/hs_service.c
+10
-5
src/or/keypin.c
src/or/keypin.c
+2
-1
src/or/nodelist.c
src/or/nodelist.c
+3
-2
src/or/onion.c
src/or/onion.c
+4
-2
src/or/onion_fast.c
src/or/onion_fast.c
+2
-1
src/or/onion_ntor.c
src/or/onion_ntor.c
+2
-1
src/or/policies.c
src/or/policies.c
+8
-4
src/or/proto_socks.c
src/or/proto_socks.c
+2
-1
src/or/protover.c
src/or/protover.c
+8
-4
src/or/relay.c
src/or/relay.c
+4
-2
src/or/rendcache.c
src/or/rendcache.c
+6
-3
src/or/rendclient.c
src/or/rendclient.c
+3
-2
src/or/rendcommon.c
src/or/rendcommon.c
+2
-1
src/or/rendservice.c
src/or/rendservice.c
+15
-8
src/or/rephist.c
src/or/rephist.c
+20
-11
src/or/router.c
src/or/router.c
+2
-2
src/or/routerkeys.c
src/or/routerkeys.c
+4
-2
src/or/routerlist.c
src/or/routerlist.c
+18
-12
src/or/routerparse.c
src/or/routerparse.c
+33
-17
src/or/routerset.c
src/or/routerset.c
+2
-1
No files found.
src/common/address.c
View file @
d52ceaa3
...
...
@@ -2133,7 +2133,8 @@ tor_addr_hostname_is_local(const char *name)
tor_addr_port_t
*
tor_addr_port_new
(
const
tor_addr_t
*
addr
,
uint16_t
port
)
{
tor_addr_port_t
*
ap
=
tor_malloc_zero
(
sizeof
(
tor_addr_port_t
));
tor_addr_port_t
*
ap
=
tor_malloc_zero_type
(
sizeof
(
tor_addr_port_t
),
TOR_STRINGIFY
(
tor_addr_port_t
));
if
(
addr
)
tor_addr_copy
(
&
ap
->
addr
,
addr
);
ap
->
port
=
port
;
...
...
src/common/aes.c
View file @
d52ceaa3
...
...
@@ -278,7 +278,8 @@ static void aes_set_iv(aes_cnt_cipher_t *cipher, const uint8_t *iv);
aes_cnt_cipher_t
*
aes_new_cipher
(
const
uint8_t
*
key
,
const
uint8_t
*
iv
,
int
bits
)
{
aes_cnt_cipher_t
*
result
=
tor_malloc_zero
(
sizeof
(
aes_cnt_cipher_t
));
aes_cnt_cipher_t
*
result
=
tor_malloc_zero_type
(
sizeof
(
aes_cnt_cipher_t
),
TOR_STRINGIFY
(
aes_cnt_cipher_t
));
aes_set_key
(
result
,
key
,
bits
);
aes_set_iv
(
result
,
iv
);
...
...
src/common/buffers.c
View file @
d52ceaa3
...
...
@@ -352,7 +352,7 @@ buf_new_with_capacity(size_t size)
buf_t
*
buf_new
(
void
)
{
buf_t
*
buf
=
tor_malloc_zero
(
sizeof
(
buf_t
));
buf_t
*
buf
=
tor_malloc_zero
_type
(
sizeof
(
buf_t
)
,
TOR_STRINGIFY
(
buf_t
)
);
buf
->
magic
=
BUFFER_MAGIC
;
buf
->
default_chunk_size
=
4096
;
return
buf
;
...
...
src/common/compat.c
View file @
d52ceaa3
...
...
@@ -284,7 +284,7 @@ tor_mmap_file(const char *filename)
return
NULL
;
}
res
=
tor_malloc_zero
(
sizeof
(
tor_mmap_t
));
res
=
tor_malloc_zero
_type
(
sizeof
(
tor_mmap_t
)
,
TOR_STRINGIFY
(
tor_mmap_t
)
);
res
->
data
=
string
;
res
->
size
=
filesize
;
res
->
mapping_size
=
size
;
...
...
@@ -318,7 +318,8 @@ tor_mmap_t *
tor_mmap_file
(
const
char
*
filename
)
{
TCHAR
tfilename
[
MAX_PATH
]
=
{
0
};
tor_mmap_t
*
res
=
tor_malloc_zero
(
sizeof
(
tor_mmap_t
));
tor_mmap_t
*
res
=
tor_malloc_zero_type
(
sizeof
(
tor_mmap_t
),
TOR_STRINGIFY
(
tor_mmap_t
));
int
empty
=
0
;
HANDLE
file_handle
=
INVALID_HANDLE_VALUE
;
DWORD
size_low
,
size_high
;
...
...
@@ -426,7 +427,7 @@ tor_mmap_file(const char *filename)
tor_mmap_t
*
handle
;
if
(
!
res
)
return
NULL
;
handle
=
tor_malloc_zero
(
sizeof
(
tor_mmap_t
));
handle
=
tor_malloc_zero
_type
(
sizeof
(
tor_mmap_t
)
,
TOR_STRINGIFY
(
tor_mmap_t
)
);
handle
->
data
=
res
;
handle
->
size
=
st
.
st_size
;
return
handle
;
...
...
@@ -957,7 +958,8 @@ tor_lockfile_lock(const char *filename, int blocking, int *locked_out)
}
#endif
/* defined(_WIN32) || ... */
result
=
tor_malloc
(
sizeof
(
tor_lockfile_t
));
result
=
tor_malloc_type
(
sizeof
(
tor_lockfile_t
),
TOR_STRINGIFY
(
tor_lockfile_t
));
result
->
filename
=
tor_strdup
(
filename
);
result
->
fd
=
fd
;
return
result
;
...
...
@@ -1844,7 +1846,7 @@ log_credential_status(void)
/* log supplementary groups */
sup_gids_size
=
64
;
sup_gids
=
tor_calloc
(
64
,
sizeof
(
gid_t
));
sup_gids
=
tor_calloc
_type
(
64
,
sizeof
(
gid_t
)
,
TOR_STRINGIFY
(
gid_t
)
);
while
((
ngids
=
getgroups
(
sup_gids_size
,
sup_gids
))
<
0
&&
errno
==
EINVAL
&&
sup_gids_size
<
NGROUPS_MAX
)
{
...
...
@@ -1894,7 +1896,8 @@ static struct passwd *passwd_cached = NULL;
static
struct
passwd
*
tor_passwd_dup
(
const
struct
passwd
*
pw
)
{
struct
passwd
*
new_pw
=
tor_malloc_zero
(
sizeof
(
struct
passwd
));
struct
passwd
*
new_pw
=
tor_malloc_zero_type
(
sizeof
(
struct
passwd
),
TOR_STRINGIFY
(
struct
passwd
));
if
(
pw
->
pw_name
)
new_pw
->
pw_name
=
tor_strdup
(
pw
->
pw_name
);
if
(
pw
->
pw_dir
)
...
...
@@ -3463,7 +3466,8 @@ tor_getpass(const char *prompt, char *output, size_t buflen)
}
tor_assert
(
buflen
<=
INT_MAX
);
wchar_t
*
buf
=
tor_calloc
(
buflen
,
sizeof
(
wchar_t
));
wchar_t
*
buf
=
tor_calloc_type
(
buflen
,
sizeof
(
wchar_t
),
TOR_STRINGIFY
(
wchar_t
));
wchar_t
*
ptr
=
buf
,
*
lastch
=
buf
+
buflen
-
1
;
while
(
ptr
<
lastch
)
{
...
...
src/common/compat_libevent.c
View file @
d52ceaa3
...
...
@@ -199,7 +199,8 @@ periodic_timer_new(struct event_base *base,
tor_assert
(
base
);
tor_assert
(
tv
);
tor_assert
(
cb
);
timer
=
tor_malloc_zero
(
sizeof
(
periodic_timer_t
));
timer
=
tor_malloc_zero_type
(
sizeof
(
periodic_timer_t
),
TOR_STRINGIFY
(
periodic_timer_t
));
if
(
!
(
timer
->
ev
=
tor_event_new
(
base
,
-
1
,
EV_PERSIST
,
periodic_timer_cb
,
timer
)))
{
tor_free
(
timer
);
...
...
src/common/compat_pthreads.c
View file @
d52ceaa3
...
...
@@ -72,7 +72,8 @@ spawn_func(void (*func)(void *), void *data)
if
(
PREDICT_UNLIKELY
(
!
threads_initialized
))
{
tor_threads_init
();
}
d
=
tor_malloc
(
sizeof
(
tor_pthread_data_t
));
d
=
tor_malloc_type
(
sizeof
(
tor_pthread_data_t
),
TOR_STRINGIFY
(
tor_pthread_data_t
));
d
->
data
=
data
;
d
->
func
=
func
;
if
(
pthread_create
(
&
thread
,
&
attr_detached
,
tor_pthread_helper_fn
,
d
))
{
...
...
src/common/compat_threads.c
View file @
d52ceaa3
...
...
@@ -33,7 +33,8 @@
tor_mutex_t
*
tor_mutex_new
(
void
)
{
tor_mutex_t
*
m
=
tor_malloc_zero
(
sizeof
(
tor_mutex_t
));
tor_mutex_t
*
m
=
tor_malloc_zero_type
(
sizeof
(
tor_mutex_t
),
TOR_STRINGIFY
(
tor_mutex_t
));
tor_mutex_init
(
m
);
return
m
;
}
...
...
@@ -42,7 +43,8 @@ tor_mutex_new(void)
tor_mutex_t
*
tor_mutex_new_nonrecursive
(
void
)
{
tor_mutex_t
*
m
=
tor_malloc_zero
(
sizeof
(
tor_mutex_t
));
tor_mutex_t
*
m
=
tor_malloc_zero_type
(
sizeof
(
tor_mutex_t
),
TOR_STRINGIFY
(
tor_mutex_t
));
tor_mutex_init_nonrecursive
(
m
);
return
m
;
}
...
...
@@ -60,7 +62,8 @@ tor_mutex_free_(tor_mutex_t *m)
tor_cond_t
*
tor_cond_new
(
void
)
{
tor_cond_t
*
cond
=
tor_malloc
(
sizeof
(
tor_cond_t
));
tor_cond_t
*
cond
=
tor_malloc_type
(
sizeof
(
tor_cond_t
),
TOR_STRINGIFY
(
tor_cond_t
));
if
(
BUG
(
tor_cond_init
(
cond
)
<
0
))
tor_free
(
cond
);
// LCOV_EXCL_LINE
return
cond
;
...
...
src/common/compress.c
View file @
d52ceaa3
...
...
@@ -474,7 +474,8 @@ tor_compress_new(int compress, compress_method_t method,
{
tor_compress_state_t
*
state
;
state
=
tor_malloc_zero
(
sizeof
(
tor_compress_state_t
));
state
=
tor_malloc_zero_type
(
sizeof
(
tor_compress_state_t
),
TOR_STRINGIFY
(
tor_compress_state_t
));
state
->
method
=
method
;
switch
(
method
)
{
...
...
src/common/compress_lzma.c
View file @
d52ceaa3
...
...
@@ -183,7 +183,8 @@ tor_lzma_compress_new(int compress,
// Note that we do not explicitly initialize the lzma_stream object here,
// since the LZMA_STREAM_INIT "just" initializes all members to 0, which is
// also what `tor_malloc_zero()` does.
result
=
tor_malloc_zero
(
sizeof
(
tor_lzma_compress_state_t
));
result
=
tor_malloc_zero_type
(
sizeof
(
tor_lzma_compress_state_t
),
TOR_STRINGIFY
(
tor_lzma_compress_state_t
));
result
->
compress
=
compress
;
result
->
allocation
=
tor_lzma_state_size_precalc
(
compress
,
level
);
...
...
src/common/compress_zlib.c
View file @
d52ceaa3
...
...
@@ -167,7 +167,8 @@ tor_zlib_compress_new(int compress_,
compression_level
=
BEST_COMPRESSION
;
}
out
=
tor_malloc_zero
(
sizeof
(
tor_zlib_compress_state_t
));
out
=
tor_malloc_zero_type
(
sizeof
(
tor_zlib_compress_state_t
),
TOR_STRINGIFY
(
tor_zlib_compress_state_t
));
out
->
stream
.
zalloc
=
Z_NULL
;
out
->
stream
.
zfree
=
Z_NULL
;
out
->
stream
.
opaque
=
NULL
;
...
...
src/common/compress_zstd.c
View file @
d52ceaa3
...
...
@@ -188,7 +188,8 @@ tor_zstd_compress_new(int compress,
tor_zstd_compress_state_t
*
result
;
size_t
retval
;
result
=
tor_malloc_zero
(
sizeof
(
tor_zstd_compress_state_t
));
result
=
tor_malloc_zero_type
(
sizeof
(
tor_zstd_compress_state_t
),
TOR_STRINGIFY
(
tor_zstd_compress_state_t
));
result
->
compress
=
compress
;
result
->
allocation
=
tor_zstd_state_size_precalc
(
compress
,
preset
);
...
...
src/common/confline.c
View file @
d52ceaa3
...
...
@@ -36,7 +36,8 @@ config_line_append(config_line_t **lst,
config_line_t
*
newline
;
newline
=
tor_malloc_zero
(
sizeof
(
config_line_t
));
newline
=
tor_malloc_zero_type
(
sizeof
(
config_line_t
),
TOR_STRINGIFY
(
config_line_t
));
newline
->
key
=
tor_strdup
(
key
);
newline
->
value
=
tor_strdup
(
val
);
newline
->
next
=
NULL
;
...
...
@@ -57,7 +58,8 @@ config_line_prepend(config_line_t **lst,
config_line_t
*
newline
;
newline
=
tor_malloc_zero
(
sizeof
(
config_line_t
));
newline
=
tor_malloc_zero_type
(
sizeof
(
config_line_t
),
TOR_STRINGIFY
(
config_line_t
));
newline
->
key
=
tor_strdup
(
key
);
newline
->
value
=
tor_strdup
(
val
);
newline
->
next
=
*
lst
;
...
...
@@ -365,7 +367,8 @@ config_lines_dup_and_filter(const config_line_t *inp,
inp
=
inp
->
next
;
continue
;
}
*
next_out
=
tor_malloc_zero
(
sizeof
(
config_line_t
));
*
next_out
=
tor_malloc_zero_type
(
sizeof
(
config_line_t
),
TOR_STRINGIFY
(
config_line_t
));
(
*
next_out
)
->
key
=
tor_strdup
(
inp
->
key
);
(
*
next_out
)
->
value
=
tor_strdup
(
inp
->
value
);
inp
=
inp
->
next
;
...
...
src/common/container.c
View file @
d52ceaa3
...
...
@@ -1524,7 +1524,8 @@ digestset_new(int max_elements)
* conserve CPU, and k==13 is pretty big.
*/
int
n_bits
=
1u
<<
(
tor_log2
(
max_elements
)
+
5
);
digestset_t
*
r
=
tor_malloc
(
sizeof
(
digestset_t
));
digestset_t
*
r
=
tor_malloc_type
(
sizeof
(
digestset_t
),
TOR_STRINGIFY
(
digestset_t
));
r
->
mask
=
n_bits
-
1
;
r
->
ba
=
bitarray_init_zero
(
n_bits
);
return
r
;
...
...
src/common/crypto.c
View file @
d52ceaa3
...
...
@@ -387,7 +387,7 @@ crypto_new_pk_from_rsa_(RSA *rsa)
{
crypto_pk_t
*
env
;
tor_assert
(
rsa
);
env
=
tor_malloc
(
sizeof
(
crypto_pk_t
));
env
=
tor_malloc
_type
(
sizeof
(
crypto_pk_t
)
,
TOR_STRINGIFY
(
crypto_pk_t
)
);
env
->
refs
=
1
;
env
->
key
=
rsa
;
return
env
;
...
...
@@ -2122,7 +2122,7 @@ crypto_xof_t *
crypto_xof_new
(
void
)
{
crypto_xof_t
*
xof
;
xof
=
tor_malloc
(
sizeof
(
crypto_xof_t
));
xof
=
tor_malloc
_type
(
sizeof
(
crypto_xof_t
)
,
TOR_STRINGIFY
(
crypto_xof_t
)
);
keccak_xof_init
(
&
xof
->
s
,
256
);
return
xof
;
}
...
...
@@ -2333,7 +2333,8 @@ init_dh_param(void)
crypto_dh_t
*
crypto_dh_new
(
int
dh_type
)
{
crypto_dh_t
*
res
=
tor_malloc_zero
(
sizeof
(
crypto_dh_t
));
crypto_dh_t
*
res
=
tor_malloc_zero_type
(
sizeof
(
crypto_dh_t
),
TOR_STRINGIFY
(
crypto_dh_t
));
tor_assert
(
dh_type
==
DH_TYPE_CIRCUIT
||
dh_type
==
DH_TYPE_TLS
||
dh_type
==
DH_TYPE_REND
);
...
...
@@ -2398,7 +2399,8 @@ crypto_dh_new(int dh_type)
crypto_dh_t
*
crypto_dh_dup
(
const
crypto_dh_t
*
dh
)
{
crypto_dh_t
*
dh_new
=
tor_malloc_zero
(
sizeof
(
crypto_dh_t
));
crypto_dh_t
*
dh_new
=
tor_malloc_zero_type
(
sizeof
(
crypto_dh_t
),
TOR_STRINGIFY
(
crypto_dh_t
));
tor_assert
(
dh
);
tor_assert
(
dh
->
dh
);
dh_new
->
dh
=
dh
->
dh
;
...
...
src/common/crypto_openssl_mgt.c
View file @
d52ceaa3
...
...
@@ -128,7 +128,8 @@ setup_openssl_threading(void)
int
i
;
int
n
=
CRYPTO_num_locks
();
n_openssl_mutexes_
=
n
;
openssl_mutexes_
=
tor_calloc
(
n
,
sizeof
(
tor_mutex_t
*
));
openssl_mutexes_
=
tor_calloc_type
(
n
,
sizeof
(
tor_mutex_t
*
),
TOR_STRINGIFY
(
tor_mutex_t
*
));
for
(
i
=
0
;
i
<
n
;
++
i
)
openssl_mutexes_
[
i
]
=
tor_mutex_new
();
CRYPTO_set_locking_callback
(
openssl_locking_cb_
);
...
...
src/common/di_ops.c
View file @
d52ceaa3
...
...
@@ -174,7 +174,8 @@ dimap_add_entry(di_digest256_map_t **map,
tor_assert
(
!
old_val
);
tor_assert
(
val
);
}
new_ent
=
tor_malloc_zero
(
sizeof
(
di_digest256_map_t
));
new_ent
=
tor_malloc_zero_type
(
sizeof
(
di_digest256_map_t
),
TOR_STRINGIFY
(
di_digest256_map_t
));
new_ent
->
next
=
*
map
;
memcpy
(
new_ent
->
key
,
key
,
32
);
new_ent
->
val
=
val
;
...
...
src/common/log.c
View file @
d52ceaa3
...
...
@@ -411,7 +411,8 @@ static pending_log_message_t *
pending_log_message_new
(
int
severity
,
log_domain_mask_t
domain
,
const
char
*
fullmsg
,
const
char
*
shortmsg
)
{
pending_log_message_t
*
m
=
tor_malloc
(
sizeof
(
pending_log_message_t
));
pending_log_message_t
*
m
=
tor_malloc_type
(
sizeof
(
pending_log_message_t
),
TOR_STRINGIFY
(
pending_log_message_t
));
m
->
severity
=
severity
;
m
->
domain
=
domain
;
m
->
fullmsg
=
fullmsg
?
tor_strdup
(
fullmsg
)
:
NULL
;
...
...
@@ -888,7 +889,7 @@ add_stream_log_impl(const log_severity_list_t *severity,
const
char
*
name
,
int
fd
)
{
logfile_t
*
lf
;
lf
=
tor_malloc_zero
(
sizeof
(
logfile_t
));
lf
=
tor_malloc_zero
_type
(
sizeof
(
logfile_t
)
,
TOR_STRINGIFY
(
logfile_t
)
);
lf
->
fd
=
fd
;
lf
->
filename
=
tor_strdup
(
name
);
lf
->
severities
=
tor_memdup
(
severity
,
sizeof
(
log_severity_list_t
));
...
...
@@ -947,7 +948,8 @@ logs_set_domain_logging(int enabled)
void
add_temp_log
(
int
min_severity
)
{
log_severity_list_t
*
s
=
tor_malloc_zero
(
sizeof
(
log_severity_list_t
));
log_severity_list_t
*
s
=
tor_malloc_zero_type
(
sizeof
(
log_severity_list_t
),
TOR_STRINGIFY
(
log_severity_list_t
));
set_log_severity_config
(
min_severity
,
LOG_ERR
,
s
);
LOCK_LOGS
();
add_stream_log_impl
(
s
,
"<temp>"
,
fileno
(
stdout
));
...
...
@@ -964,7 +966,7 @@ int
add_callback_log
(
const
log_severity_list_t
*
severity
,
log_callback
cb
)
{
logfile_t
*
lf
;
lf
=
tor_malloc_zero
(
sizeof
(
logfile_t
));
lf
=
tor_malloc_zero
_type
(
sizeof
(
logfile_t
)
,
TOR_STRINGIFY
(
logfile_t
)
);
lf
->
fd
=
-
1
;
lf
->
severities
=
tor_memdup
(
severity
,
sizeof
(
log_severity_list_t
));
lf
->
filename
=
tor_strdup
(
"<callback>"
);
...
...
@@ -1184,7 +1186,7 @@ add_syslog_log(const log_severity_list_t *severity,
openlog
(
buf
,
LOG_PID
|
LOG_NDELAY
,
LOGFACILITY
);
}
lf
=
tor_malloc_zero
(
sizeof
(
logfile_t
));
lf
=
tor_malloc_zero
_type
(
sizeof
(
logfile_t
)
,
TOR_STRINGIFY
(
logfile_t
)
);
lf
->
fd
=
-
1
;
lf
->
severities
=
tor_memdup
(
severity
,
sizeof
(
log_severity_list_t
));
lf
->
filename
=
tor_strdup
(
"<syslog>"
);
...
...
@@ -1209,7 +1211,7 @@ add_android_log(const log_severity_list_t *severity,
{
logfile_t
*
lf
=
NULL
;
lf
=
tor_malloc_zero
(
sizeof
(
logfile_t
));
lf
=
tor_malloc_zero
_type
(
sizeof
(
logfile_t
)
,
TOR_STRINGIFY
(
logfile_t
)
);
lf
->
fd
=
-
1
;
lf
->
severities
=
tor_memdup
(
severity
,
sizeof
(
log_severity_list_t
));
lf
->
filename
=
tor_strdup
(
"<android>"
);
...
...
src/common/memarea.c
View file @
d52ceaa3
...
...
@@ -145,7 +145,8 @@ memarea_chunk_free_unchecked(memarea_chunk_t *chunk)
memarea_t
*
memarea_new
(
void
)
{
memarea_t
*
head
=
tor_malloc
(
sizeof
(
memarea_t
));
memarea_t
*
head
=
tor_malloc_type
(
sizeof
(
memarea_t
),
TOR_STRINGIFY
(
memarea_t
));
head
->
first
=
alloc_chunk
(
CHUNK_SIZE
);
return
head
;
}
...
...
@@ -317,7 +318,8 @@ struct memarea_t {
memarea_t
*
memarea_new
(
void
)
{
memarea_t
*
ma
=
tor_malloc_zero
(
sizeof
(
memarea_t
));
memarea_t
*
ma
=
tor_malloc_zero_type
(
sizeof
(
memarea_t
),
TOR_STRINGIFY
(
memarea_t
));
ma
->
pieces
=
smartlist_new
();
return
ma
;
}
...
...
src/common/procmon.c
View file @
d52ceaa3
...
...
@@ -181,8 +181,8 @@ tor_process_monitor_new(struct event_base *base,
tor_procmon_callback_t
cb
,
void
*
cb_arg
,
const
char
**
msg
)
{
tor_process_monitor_t
*
procmon
=
tor_malloc_zero
(
sizeof
(
tor_process_monitor_t
));
tor_process_monitor_t
*
procmon
=
tor_malloc_zero
_type
(
sizeof
(
tor_process_monitor_t
),
TOR_STRINGIFY
(
tor_process_monitor_t
));
struct
parsed_process_specifier_t
ppspec
;
tor_assert
(
msg
!=
NULL
);
...
...
src/common/sandbox.c
View file @
d52ceaa3
...
...
@@ -1370,8 +1370,10 @@ new_element2(int syscall, char *value, char *value2)
{
smp_param_t
*
param
=
NULL
;
sandbox_cfg_t
*
elem
=
tor_malloc_zero
(
sizeof
(
sandbox_cfg_t
));
param
=
elem
->
param
=
tor_malloc_zero
(
sizeof
(
smp_param_t
));
sandbox_cfg_t
*
elem
=
tor_malloc_zero_type
(
sizeof
(
sandbox_cfg_t
),
TOR_STRINGIFY
(
sandbox_cfg_t
));
param
=
elem
->
param
=
tor_malloc_zero_type
(
sizeof
(
smp_param_t
),
TOR_STRINGIFY
(
smp_param_t
));
param
->
syscall
=
syscall
;
param
->
value
=
value
;
...
...
src/common/storagedir.c
View file @
d52ceaa3
...
...
@@ -49,7 +49,8 @@ storage_dir_new(const char *dirname, int max_files)
if
(
check_private_dir
(
dirname
,
CPD_CREATE
,
NULL
)
<
0
)
return
NULL
;
storage_dir_t
*
d
=
tor_malloc_zero
(
sizeof
(
storage_dir_t
));
storage_dir_t
*
d
=
tor_malloc_zero_type
(
sizeof
(
storage_dir_t
),
TOR_STRINGIFY
(
storage_dir_t
));
d
->
directory
=
tor_strdup
(
dirname
);
d
->
max_files
=
max_files
;
return
d
;
...
...
@@ -535,7 +536,9 @@ storage_dir_shrink(storage_dir_t *d,
}
const
int
n
=
smartlist_len
(
d
->
contents
);
shrinking_dir_entry_t
*
ents
=
tor_calloc
(
n
,
sizeof
(
shrinking_dir_entry_t
));
shrinking_dir_entry_t
*
ents
=
tor_calloc_type
(
n
,
sizeof
(
shrinking_dir_entry_t
),
TOR_STRINGIFY
(
shrinking_dir_entry_t
));
SMARTLIST_FOREACH_BEGIN
(
d
->
contents
,
const
char
*
,
fname
)
{
shrinking_dir_entry_t
*
ent
=
&
ents
[
fname_sl_idx
];
struct
stat
st
;
...
...
src/common/timers.c
View file @
d52ceaa3
...
...
@@ -234,7 +234,8 @@ timers_shutdown(void)
tor_timer_t
*
timer_new
(
timer_cb_fn_t
cb
,
void
*
arg
)
{
tor_timer_t
*
t
=
tor_malloc
(
sizeof
(
tor_timer_t
));
tor_timer_t
*
t
=
tor_malloc_type
(
sizeof
(
tor_timer_t
),
TOR_STRINGIFY
(
tor_timer_t
));
timeout_init
(
t
,
0
);
timer_set_cb
(
t
,
cb
,
arg
);
return
t
;
...
...
src/common/tortls.c
View file @
d52ceaa3
...
...
@@ -1119,7 +1119,8 @@ tor_tls_context_new(crypto_pk_t *identity, unsigned int key_lifetime,
}
}
result
=
tor_malloc_zero
(
sizeof
(
tor_tls_context_t
));
result
=
tor_malloc_zero_type
(
sizeof
(
tor_tls_context_t
),
TOR_STRINGIFY
(
tor_tls_context_t
));
result
->
refcnt
=
1
;
if
(
!
is_client
)
{
result
->
my_link_cert
=
tor_x509_cert_new
(
X509_dup
(
cert
));
...
...
@@ -1632,7 +1633,8 @@ tor_tls_t *
tor_tls_new
(
int
sock
,
int
isServer
)
{
BIO
*
bio
=
NULL
;
tor_tls_t
*
result
=
tor_malloc_zero
(
sizeof
(
tor_tls_t
));
tor_tls_t
*
result
=
tor_malloc_zero_type
(
sizeof
(
tor_tls_t
),
TOR_STRINGIFY
(
tor_tls_t
));
tor_tls_context_t
*
context
=
isServer
?
server_tls_context
:
client_tls_context
;
result
->
magic
=
TOR_TLS_MAGIC
;
...
...
src/common/util.c
View file @
d52ceaa3
...
...
@@ -180,6 +180,31 @@ tor_malloc_zero_(size_t size DMALLOC_PARAMS)
return
result
;
}
void
*
tor_malloc_type_
(
size_t
size
,
const
char
*
t
)
{
tor_malloc_increment_stats
(
t
,
1
,
size
);
return
tor_malloc_
(
size
);
}
void
*
tor_malloc_zero_type_
(
size_t
size
,
const
char
*
t
)
{
tor_malloc_increment_stats
(
t
,
1
,
size
);
return
tor_malloc_zero_
(
size
);
}
void
*
tor_calloc_type_
(
size_t
nmemb
,
size_t
size
,
const
char
*
t
)
{
tor_malloc_increment_stats
(
t
,
nmemb
,
size
);
return
tor_calloc_
(
nmemb
,
size
);
}
void
tor_malloc_increment_stats
(
const
char
*
type
,
size_t
count
,
size_t
size
)
{
(
void
)
type
;
(
void
)
count
;
(
void
)
size
;
}
/* The square root of SIZE_MAX + 1. If a is less than this, and b is less
* than this, then a*b is less than SIZE_MAX. (For example, if size_t is
* 32 bits, then SIZE_MAX is 0xffffffff and this value is 0x10000. If a and
...
...
@@ -2511,7 +2536,8 @@ int
start_writing_to_file
(
const
char
*
fname
,
int
open_flags
,
int
mode
,
open_file_t
**
data_out
)
{
open_file_t
*
new_file
=
tor_malloc_zero
(
sizeof
(
open_file_t
));
open_file_t
*
new_file
=
tor_malloc_zero_type
(
sizeof
(
open_file_t
),
TOR_STRINGIFY
(
open_file_t
));
const
char
*
open_name
;
int
append
=
0
;
...
...
@@ -4097,7 +4123,8 @@ tor_process_get_stdout_pipe(process_handle_t *process_handle)
static
process_handle_t
*
process_handle_new
(
void
)
{
process_handle_t
*
out
=
tor_malloc_zero
(
sizeof
(
process_handle_t
));
process_handle_t
*
out
=
tor_malloc_zero_type
(
sizeof
(
process_handle_t
),
TOR_STRINGIFY
(
process_handle_t
));
#ifdef _WIN32
out
->
stdin_pipe
=
INVALID_HANDLE_VALUE
;
...
...
@@ -4734,14 +4761,17 @@ process_environment_free_(process_environment_t *env)
process_environment_t
*
process_environment_make
(
struct
smartlist_t
*
env_vars
)
{
process_environment_t
*
env
=
tor_malloc_zero
(
sizeof
(
process_environment_t
));
process_environment_t
*
env
=
tor_malloc_zero_type
(
sizeof
(
process_environment_t
),
TOR_STRINGIFY
(
process_environment_t
));
size_t
n_env_vars
=
smartlist_len
(
env_vars
);
size_t
i
;
size_t
total_env_length
;
smartlist_t
*
env_vars_sorted
;
tor_assert
(
n_env_vars
+
1
!=
0
);
env
->
unixoid_environment_block
=
tor_calloc
(
n_env_vars
+
1
,
sizeof
(
char
*
));
env
->
unixoid_environment_block
=
tor_calloc_type
(
n_env_vars
+
1
,
sizeof
(
char
*
),
TOR_STRINGIFY
(
char
*
));
/* env->unixoid_environment_block is already NULL-terminated,
* because we assume that NULL == 0 (and check that during compilation). */
...
...
@@ -5476,7 +5506,7 @@ tor_check_port_forwarding(const char *filename,
for each smartlist element (one for "-p" and one for the
ports), and one for the final NULL. */
args_n
=
1
+
2
*
smartlist_len
(
ports_to_forward
)
+
1
;
argv
=
tor_calloc
(
args_n
,
sizeof
(
char
*
));
argv
=
tor_calloc
_type
(
args_n
,
sizeof
(
char
*
),
TOR_STRINGIFY
(
char
*
));
argv
[
argv_index
++
]
=
filename
;
SMARTLIST_FOREACH_BEGIN
(
ports_to_forward
,
const
char
*
,
port
)
{
...
...
src/common/util.h
View file @
d52ceaa3
...
...
@@ -114,6 +114,16 @@ extern int dmalloc_free(const char *file, const int line, void *pnt,
#define tor_memdup(s, n) tor_memdup_(s, n DMALLOC_ARGS)
#define tor_memdup_nulterm(s, n) tor_memdup_nulterm_(s, n DMALLOC_ARGS)
void
*
tor_malloc_type_
(
size_t
size
,
const
char
*
t
)
ATTR_MALLOC
;
void
*
tor_malloc_zero_type_
(
size_t
size
,
const
char
*
t
)
ATTR_MALLOC
;
void
*
tor_calloc_type_
(
size_t
nmemb
,
size_t
size
,
const
char
*
t
)
ATTR_MALLOC
;
#define tor_malloc_type(size, t) tor_malloc_type_(size, t)
#define tor_malloc_zero_type(size, t) tor_malloc_zero_type_(size, t)
#define tor_calloc_type(nmemb,size, t) tor_calloc_type_(nmemb, size, t)
void
tor_malloc_increment_stats
(
const
char
*
type
,
size_t
count
,
size_t
size
);
/* Aliases for the underlying system malloc/realloc/free. Only use
* them to indicate "I really want the underlying system function, I know
* what I'm doing." */
...
...
src/common/workqueue.c
View file @
d52ceaa3
...
...
@@ -140,7 +140,8 @@ workqueue_entry_new(workqueue_reply_t (*fn)(void*, void*),
void
(
*
reply_fn
)(
void
*
),
void
*
arg
)
{
workqueue_entry_t
*
ent
=
tor_malloc_zero
(
sizeof
(
workqueue_entry_t
));
workqueue_entry_t
*
ent
=
tor_malloc_zero_type
(
sizeof
(
workqueue_entry_t
),
TOR_STRINGIFY
(
workqueue_entry_t
));
ent
->
fn
=
fn
;
ent
->
reply_fn
=
reply_fn
;
ent
->
arg
=
arg
;
...
...
@@ -333,7 +334,8 @@ static workerthread_t *
workerthread_new
(
int32_t
lower_priority_chance
,
void
*
state
,
threadpool_t
*
pool
,
replyqueue_t
*
replyqueue
)
{
workerthread_t
*
thr
=
tor_malloc_zero
(
sizeof
(
workerthread_t
));
workerthread_t
*
thr
=
tor_malloc_zero_type
(
sizeof
(
workerthread_t
),
TOR_STRINGIFY
(
workerthread_t
));
thr
->
state
=
state
;
thr
->
reply_queue
=
replyqueue
;
thr
->
in_pool
=
pool
;
...
...
@@ -441,7 +443,7 @@ threadpool_queue_update(threadpool_t *pool,
old_args
=
pool
->
update_args
;
old_args_free_fn
=
pool
->
free_update_arg_fn
;
new_args
=
tor_calloc
(
n_threads
,
sizeof
(
void
*
));
new_args
=
tor_calloc
_type
(
n_threads
,
sizeof
(
void
*
),
TOR_STRINGIFY
(
void
*
));
for
(
i
=
0
;
i
<
n_threads
;
++
i
)
{
if
(
dup_fn
)
new_args
[
i
]
=
dup_fn
(
arg
);
...
...
@@ -536,7 +538,8 @@ threadpool_new(int n_threads,
void
*
arg
)
{
threadpool_t
*
pool
;