mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Never call free() on tor_malloc()d memory. This is unlikely to be our current leak, but it may help dmalloc work.
svn:r5168
This commit is contained in:
+1
-1
@@ -157,7 +157,7 @@ aes_free_cipher(aes_cnt_cipher_t *cipher)
|
||||
{
|
||||
assert(cipher);
|
||||
memset(cipher, 0, sizeof(cipher));
|
||||
free(cipher);
|
||||
tor_free(cipher);
|
||||
}
|
||||
|
||||
/** Encrypt <b>len</b> bytes from <b>input</b>, storing the result in
|
||||
|
||||
@@ -58,8 +58,8 @@ smartlist_create(void)
|
||||
void
|
||||
smartlist_free(smartlist_t *sl)
|
||||
{
|
||||
free(sl->list);
|
||||
free(sl);
|
||||
tor_free(sl->list);
|
||||
tor_free(sl);
|
||||
}
|
||||
|
||||
/** Change the capacity of the smartlist to <b>n</b>, so that we can grow
|
||||
|
||||
+7
-7
@@ -323,7 +323,7 @@ crypto_free_pk_env(crypto_pk_env_t *env)
|
||||
if (env->key)
|
||||
RSA_free(env->key);
|
||||
|
||||
free(env);
|
||||
tor_free(env);
|
||||
}
|
||||
|
||||
/** Create a new symmetric cipher for a given key and encryption flag
|
||||
@@ -561,7 +561,7 @@ crypto_pk_write_private_key_to_filename(crypto_pk_env_t *env,
|
||||
s[len]='\0';
|
||||
r = write_str_to_file(fname, s, 0);
|
||||
BIO_free(bio);
|
||||
free(s);
|
||||
tor_free(s);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1032,14 +1032,14 @@ crypto_pk_get_digest(crypto_pk_env_t *pk, char *digest_out)
|
||||
len = i2d_RSAPublicKey(pk->key, &bufp);
|
||||
if (len < 0) {
|
||||
crypto_log_errors(LOG_WARN,"encoding public key");
|
||||
free(buf);
|
||||
tor_free(buf);
|
||||
return -1;
|
||||
}
|
||||
if (crypto_digest(digest_out, (char*)buf, len) < 0) {
|
||||
free(buf);
|
||||
tor_free(buf);
|
||||
return -1;
|
||||
}
|
||||
free(buf);
|
||||
tor_free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1367,7 +1367,7 @@ crypto_dh_new(void)
|
||||
err:
|
||||
crypto_log_errors(LOG_WARN, "creating DH object");
|
||||
if (res && res->dh) DH_free(res->dh); /* frees p and g too */
|
||||
if (res) free(res);
|
||||
if (res) tor_free(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1564,7 +1564,7 @@ crypto_dh_free(crypto_dh_env_t *dh)
|
||||
tor_assert(dh);
|
||||
tor_assert(dh->dh);
|
||||
DH_free(dh->dh);
|
||||
free(dh);
|
||||
tor_free(dh);
|
||||
}
|
||||
|
||||
/* random numbers */
|
||||
|
||||
+1
-1
@@ -408,7 +408,7 @@ tor_tls_context_new(crypto_pk_env_t *identity,
|
||||
if (result && result->client_only_ctx)
|
||||
SSL_CTX_free(result->client_only_ctx);
|
||||
if (result)
|
||||
free(result);
|
||||
tor_free(result);
|
||||
if (cert)
|
||||
X509_free(cert);
|
||||
if (idcert)
|
||||
|
||||
+9
-6
@@ -83,14 +83,15 @@ buf_normalize(buf_t *buf)
|
||||
if (buf->cur + buf->datalen <= buf->mem+buf->len) {
|
||||
return;
|
||||
} else {
|
||||
char *newmem;
|
||||
char *newmem, *oldmem;
|
||||
size_t sz = (buf->mem+buf->len)-buf->cur;
|
||||
log_fn(LOG_WARN, "Unexpected non-normalized buffer.");
|
||||
newmem = GUARDED_MEM(tor_malloc(ALLOC_LEN(buf->len)));
|
||||
SET_GUARDS(newmem, buf->len);
|
||||
memcpy(newmem, buf->cur, sz);
|
||||
memcpy(newmem+sz, buf->mem, buf->datalen-sz);
|
||||
free(RAW_MEM(buf->mem));
|
||||
oldmem = RAW_MEM(buf->mem);
|
||||
tor_free(oldmem); /* Can't use tor_free directly. */
|
||||
buf->mem = buf->cur = newmem;
|
||||
check();
|
||||
}
|
||||
@@ -196,11 +197,11 @@ buf_resize(buf_t *buf, size_t new_capacity)
|
||||
!buf->datalen &&
|
||||
buf->len >= 1<<16) {
|
||||
/* don't realloc; free and malloc */
|
||||
char *newmem = GUARDED_MEM(tor_malloc(ALLOC_LEN(new_capacity)));
|
||||
char *oldmem, *newmem = GUARDED_MEM(tor_malloc(ALLOC_LEN(new_capacity)));
|
||||
SET_GUARDS(newmem, new_capacity);
|
||||
free(RAW_MEM(buf->mem));
|
||||
oldmem = RAW_MEM(buf->mem);
|
||||
tor_free(oldmem);
|
||||
buf->mem = buf->cur = newmem;
|
||||
|
||||
} else {
|
||||
buf->mem = GUARDED_MEM(tor_realloc(RAW_MEM(buf->mem),
|
||||
ALLOC_LEN(new_capacity)));
|
||||
@@ -371,9 +372,11 @@ _buf_peek_raw_buffer(const buf_t *buf)
|
||||
void
|
||||
buf_free(buf_t *buf)
|
||||
{
|
||||
char *oldmem;
|
||||
assert_buf_ok(buf);
|
||||
buf->magic = 0xDEADBEEF;
|
||||
free(RAW_MEM(buf->mem));
|
||||
oldmem = RAW_MEM(buf->mem);
|
||||
tor_free(oldmem);
|
||||
buf_total_alloc -= buf->len;
|
||||
buf_total_used -= buf->datalen;
|
||||
tor_free(buf);
|
||||
|
||||
+3
-3
@@ -1464,7 +1464,7 @@ nt_torrc_is_present()
|
||||
path_to_torrc = tor_malloc(len);
|
||||
if (tor_snprintf(path_to_torrc, len, "%s%s%s", szDrive, szDir, torrc)<0) {
|
||||
printf("Failed: tor_snprinf()\n");
|
||||
free(path_to_torrc);
|
||||
tor_free(path_to_torrc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1772,7 +1772,7 @@ nt_service_install(void)
|
||||
}
|
||||
|
||||
if ((hSCManager = nt_service_open_scm()) == NULL) {
|
||||
free(command);
|
||||
tor_free(command);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1789,7 +1789,7 @@ nt_service_install(void)
|
||||
printf("CreateService() failed : %s\n", errmsg);
|
||||
CloseServiceHandle(hSCManager);
|
||||
LocalFree(errmsg);
|
||||
free(command);
|
||||
tor_free(command);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -543,9 +543,9 @@ test_crypto(void)
|
||||
test_eq(i,0);
|
||||
test_memeq(data2, "\xf0\xd6\x78\xaf\xfc\x00\x01\x00",8);
|
||||
|
||||
free(data1);
|
||||
free(data2);
|
||||
free(data3);
|
||||
tor_free(data1);
|
||||
tor_free(data2);
|
||||
tor_free(data3);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user