introduce htmalloc

This commit is contained in:
whottgen
2004-10-15 11:18:48 +00:00
parent ec14ad4e99
commit ae46b70398
17 changed files with 167 additions and 66 deletions

View File

@ -46,7 +46,7 @@
#include "htdns.h"
#include "queue.h"
#include "smtp.h"
#include "htmalloc.h"
#define SMM_LOCAL_PERM_NOK 101
@ -160,7 +160,7 @@ class_descriptor_t verifier = {
int verify_init(cfgl_t *cfg, void **handle) {
verify_container_handle_t *vch;
vch = (verify_container_handle_t*) malloc(sizeof(verify_container_handle_t));
vch = (verify_container_handle_t*) htmalloc(sizeof(verify_container_handle_t));
vch->cfg = cfg;
vch->timeout_result = atoi(findcfglx(vch->cfg, "timeout_result", "5"));
@ -174,7 +174,7 @@ int verify_init(cfgl_t *cfg, void **handle) {
vch->cache_file = findcfglx(vch->cfg, "cache_file", "verifier_cache");
if (1 == vch->cache_enabled) {
vch->cache_mutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
vch->cache_mutex = (pthread_mutex_t*) htmalloc(sizeof(pthread_mutex_t));
pthread_mutex_init(vch->cache_mutex, NULL);
pthread_mutex_unlock(vch->cache_mutex);
} else {
@ -204,15 +204,15 @@ int verify_destroy(void *handle) {
int verify_work_setup(void *handle, void **work_handle) {
verify_work_handle_t *vwh;
vwh = (verify_work_handle_t*)malloc(sizeof(verify_work_handle_t));
vwh = (verify_work_handle_t*)htmalloc(sizeof(verify_work_handle_t));
vwh->id = 0;
vwh->result = (verify_result_t*) malloc(sizeof(verify_result_t));
vwh->result_mutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
vwh->result = (verify_result_t*) htmalloc(sizeof(verify_result_t));
vwh->result_mutex = (pthread_mutex_t*) htmalloc(sizeof(pthread_mutex_t));
pthread_mutex_init(vwh->result_mutex, NULL);
pthread_mutex_unlock(vwh->result_mutex);
vwh->result_cond = (pthread_cond_t*) malloc(sizeof(pthread_cond_t));
vwh->result_cond = (pthread_cond_t*) htmalloc(sizeof(pthread_cond_t));
pthread_cond_init(vwh->result_cond, NULL);
vwh->terminator_queue = (ht_queue_t*) malloc(sizeof(ht_queue_t));
vwh->terminator_queue = (ht_queue_t*) htmalloc(sizeof(ht_queue_t));
queue_init(vwh->terminator_queue);
vwh->vch = (verify_container_handle_t*)handle;
@ -295,7 +295,7 @@ void cache_insert(verify_container_handle_t *vch, const char *address, int resul
key.dsize = strlen(address) + 1; /* one more for the terminating \0 */
key.dptr = (char*) address;
data.dsize = (sizeof(mydata_t) + (sizeof(char) * (strlen(output) + 1)));
mydata = (mydata_t *) malloc(data.dsize);
mydata = (mydata_t *) htmalloc(data.dsize);
mydata->result = result;
mydata->timestamp = time(NULL);
strcpy(mydata->output, output);
@ -345,7 +345,7 @@ int cache_lookup(verify_container_handle_t *vch, const char* address, int *resul
if ((mydata->timestamp + vch->cache_expiry) > time(NULL)) {
syslog(LOG_DEBUG, "cache_lookup: not yet expired");
*result = mydata->result;
*output = (char*) malloc(sizeof(char) * (strlen(mydata->output) + 1));
*output = (char*) htmalloc(sizeof(char) * (strlen(mydata->output) + 1));
strcpy(*output, mydata->output);
/* Berkeley DB frees on its own! */
@ -429,16 +429,16 @@ int verify_work(void *handle, void *work_handle, char *input, char *output) {
vwh->result->id = vwh->id;
wt = (worker_thread_t*) malloc(sizeof(worker_thread_t));
wt = (worker_thread_t*) htmalloc(sizeof(worker_thread_t));
wt->id = vwh->id;
wt->terminator_queue = vwh->terminator_queue;
wt->input = (char*) malloc(sizeof(char) * (strlen(input)+1));
wt->input = (char*) htmalloc(sizeof(char) * (strlen(input)+1));
strcpy(wt->input, input);
wt->output = NULL;
wt->mutex = vwh->result_mutex;
wt->cond = vwh->result_cond;
wt->result = vwh->result;
wt->checker_terminator_queue = (ht_queue_t*) malloc(sizeof(ht_queue_t));
wt->checker_terminator_queue = (ht_queue_t*) htmalloc(sizeof(ht_queue_t));
queue_init(wt->checker_terminator_queue);
wt->checker_cnt = 0;
wt->vwh = work_handle;
@ -486,7 +486,7 @@ static unsigned int *get_mx_ip_addresses(char *domain) {
a_rdata = get_a_rrs((*mx_rdata2)->exchange);
if (NULL != a_rdata) {
for (a_rdata2 = a_rdata; *a_rdata2 != NULL; a_rdata2++) {
addresses = (unsigned int*)realloc(addresses, sizeof(unsigned int)*(i+2)); /* 2 since first i==0 and
addresses = (unsigned int*)htrealloc(addresses, sizeof(unsigned int)*(i+2)); /* 2 since first i==0 and
we always need one more
for the termination */
*(addresses+i) = (*a_rdata2)->address;
@ -555,7 +555,7 @@ static void *checker_thread(void *arg) {
err = smtp_mailfrom(smtp, sender_address);
break;
case RCPTTO:
tmp_arg = (char*) malloc(sizeof(char) * (strlen(ct->email_address)+5));
tmp_arg = (char*) htmalloc(sizeof(char) * (strlen(ct->email_address)+5));
*tmp_arg = '\0';
strcat(tmp_arg, "<");
strcat(tmp_arg, ct->email_address);
@ -624,7 +624,7 @@ static void *checker_thread(void *arg) {
smtp_close(smtp);
ct->output = (char*) malloc(sizeof(char) * (strlen(response_text)+1));
ct->output = (char*) htmalloc(sizeof(char) * (strlen(response_text)+1));
strcpy(ct->output, response_text);
smtp_destroy(smtp);
@ -688,7 +688,7 @@ static void *worker_thread(void *arg) {
(address&0x0000ff00)>>8, (address&0x000000ff),
wt->input);
ct = (checker_thread_t*) malloc(sizeof(checker_thread_t));
ct = (checker_thread_t*) htmalloc(sizeof(checker_thread_t));
ct->id = i+1; /* id of ct should start with 1, same as id of wt */
ct->ip_address = address;
ct->email_address = wt->input;
@ -752,7 +752,7 @@ static void *worker_thread(void *arg) {
if (wt->result->id == wt->id) {
syslog(LOG_DEBUG, "verify (%p) worker_thread %d returned result", wt->vwh, wt->id);
/* we can write the result */
wt->result->output = (char*) malloc(sizeof(char) * (strlen(wt->output)+15)); /* enough for the output
wt->result->output = (char*) htmalloc(sizeof(char) * (strlen(wt->output)+15)); /* enough for the output
plus <><> and prefix */
switch (result) {
case SMM_LOCAL_TEMP_NOK: