summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/aes.c2
-rw-r--r--src/common/container.c4
-rw-r--r--src/common/crypto.c14
-rw-r--r--src/common/tortls.c2
-rw-r--r--src/or/buffers.c15
-rw-r--r--src/or/main.c6
-rw-r--r--src/or/test.c6
7 files changed, 26 insertions, 23 deletions
diff --git a/src/common/aes.c b/src/common/aes.c
index b4dd774755..71250cd0c5 100644
--- a/src/common/aes.c
+++ b/src/common/aes.c
@@ -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
diff --git a/src/common/container.c b/src/common/container.c
index 39cabe9c5d..88f0ca4336 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -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
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 38e9931f88..eaa002e7ba 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -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 */
diff --git a/src/common/tortls.c b/src/common/tortls.c
index d2b0d7080d..84bcf5a5a9 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -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)
diff --git a/src/or/buffers.c b/src/or/buffers.c
index a3b33a707b..e3b5c75ca2 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -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);
diff --git a/src/or/main.c b/src/or/main.c
index 42b4962ee0..836b585569 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -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;
}
diff --git a/src/or/test.c b/src/or/test.c
index 71be68d3df..6af607a7e3 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -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