summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroel <roel@7b491191-dbf0-0310-aff6-d879d4d69008>2001-11-14 14:50:19 +0000
committerroel <roel@7b491191-dbf0-0310-aff6-d879d4d69008>2001-11-14 14:50:19 +0000
commitfe4d9159e5d1798adce9cdbef9ca6bcd5703c4c8 (patch)
tree0038fada058d4f6319e55bcd7687711c8f1fcb7d
parent933238fc8f46ddf9d6591820325a6ed020550729 (diff)
*** empty log message ***
git-svn-id: https://svn.ic-s.nl/svn/dbmail/trunk/dbmail@327 7b491191-dbf0-0310-aff6-d879d4d69008
-rw-r--r--dbmysql.c104
-rw-r--r--debug.c113
-rw-r--r--debug.h9
-rw-r--r--imap4.c14
-rw-r--r--imapcommands.c82
-rw-r--r--imapd.c22
-rw-r--r--imaputil.c44
-rw-r--r--list.c16
-rw-r--r--mime.c30
9 files changed, 280 insertions, 154 deletions
diff --git a/dbmysql.c b/dbmysql.c
index d059069c..f6467a84 100644
--- a/dbmysql.c
+++ b/dbmysql.c
@@ -239,7 +239,7 @@ char *db_get_config_item (char *item, int type)
if (row[0]!=NULL)
{
- result=(char *)malloc(strlen(row[0])+1);
+ result=(char *)my_malloc(strlen(row[0])+1);
if (result!=NULL)
strcpy (result,row[0]);
trace (TRACE_DEBUG,"Ok result [%s]\n",result);
@@ -393,7 +393,7 @@ char *db_get_userid (unsigned long *useridnr)
if (row[0])
{
- if (!(returnid = (char *)malloc(strlen(row[0])+1)))
+ if (!(returnid = (char *)my_malloc(strlen(row[0])+1)))
{
trace(TRACE_ERROR,"db_get_userid(): out of memory");
mysql_free_result(res);
@@ -599,13 +599,13 @@ unsigned long db_insert_message_block (char *block, int messageidnr)
/* allocate memory twice as much, for eacht character might be escaped
added aditional 250 bytes for possible function err */
- memtst((escblk=(char *)malloc(((len*2)+250)))==NULL);
+ memtst((escblk=(char *)my_malloc(((len*2)+250)))==NULL);
/* escape the string */
if ((esclen = mysql_escape_string(escblk, block, len)) > 0)
{
/* add an extra 500 characters for the query */
- memtst((tmpquery=(char *)malloc(esclen + 500))==NULL);
+ memtst((tmpquery=(char *)my_malloc(esclen + 500))==NULL);
snprintf (tmpquery, esclen+500,
"INSERT INTO messageblk(messageblk,blocksize,messageidnr) "
@@ -614,15 +614,15 @@ unsigned long db_insert_message_block (char *block, int messageidnr)
if (db_query (tmpquery)==-1)
{
- free(escblk);
- free(tmpquery);
+ my_free(escblk);
+ my_free(tmpquery);
trace(TRACE_ERROR,"db_insert_message_block(): dbquery failed\n");
return -1;
}
/* freeing buffers */
- free (tmpquery);
- free (escblk);
+ my_free(tmpquery);
+ my_free(escblk);
return db_insert_result();
}
else
@@ -630,7 +630,7 @@ unsigned long db_insert_message_block (char *block, int messageidnr)
trace (TRACE_ERROR,"db_insert_message_block(): mysql_real_escape_string() "
"returned empty value\n");
- free(escblk);
+ my_free(escblk);
return -1;
}
}
@@ -705,7 +705,7 @@ int db_send_message_lines (void *fstream, unsigned long messageidnr, long lines,
trace (TRACE_DEBUG,"db_send_message_lines(): request for [%d] lines",lines);
- memtst ((buffer=(char *)malloc(READ_BLOCK_SIZE*2))==NULL);
+ memtst ((buffer=(char *)my_malloc(READ_BLOCK_SIZE*2))==NULL);
snprintf (query, DEF_QUERYSIZE,
"SELECT * FROM messageblk WHERE messageidnr=%lu ORDER BY messageblknr ASC",
@@ -714,14 +714,14 @@ int db_send_message_lines (void *fstream, unsigned long messageidnr, long lines,
if (db_query(query)==-1)
{
- free (buffer);
+ my_free(buffer);
return 0;
}
if ((res = mysql_store_result(&conn)) == NULL)
{
trace(TRACE_ERROR,"db_send_message_lines: mysql_store_result failed: %s",mysql_error(&conn));
- free (buffer);
+ my_free(buffer);
return 0;
}
@@ -812,7 +812,7 @@ int db_send_message_lines (void *fstream, unsigned long messageidnr, long lines,
mysql_free_result(res);
- free (buffer);
+ my_free(buffer);
return 1;
}
@@ -889,7 +889,7 @@ unsigned long db_md5_validate (char *username,unsigned char *md5_apop_he, char *
trace (TRACE_DEBUG,"db_md5_validate(): apop_stamp=[%s], userpw=[%s]",apop_stamp,row[0]);
- memtst((checkstring=(char *)malloc(strlen(apop_stamp)+strlen(row[0])+2))==NULL);
+ memtst((checkstring=(char *)my_malloc(strlen(apop_stamp)+strlen(row[0])+2))==NULL);
snprintf(checkstring, strlen(apop_stamp)+strlen(row[0])+2, "%s%s",apop_stamp,row[0]);
md5_apop_we=makemd5(checkstring);
@@ -907,7 +907,7 @@ unsigned long db_md5_validate (char *username,unsigned char *md5_apop_he, char *
mysql_free_result(res);
- free(checkstring);
+ my_free(checkstring);
return useridnr;
}
@@ -918,7 +918,7 @@ unsigned long db_md5_validate (char *username,unsigned char *md5_apop_he, char *
mysql_free_result(res);
- free(checkstring);
+ my_free(checkstring);
return 0;
}
@@ -1431,7 +1431,7 @@ int db_imap_append_msg(char *msgdata, unsigned long datalen, unsigned long mboxi
if (db_query(query) == -1)
{
trace(TRACE_ERROR, "db_imap_append_msg(): could not create message\n");
- free(query);
+ my_free(query);
return -1;
}
@@ -1670,7 +1670,7 @@ int db_findmailbox_by_regex(unsigned long ownerid, const char *pattern,
}
/* alloc mem */
- tmp = (unsigned long *)malloc(sizeof(unsigned long) * mysql_num_rows(res));
+ tmp = (unsigned long *)my_malloc(sizeof(unsigned long) * mysql_num_rows(res));
if (!tmp)
{
trace(TRACE_ERROR,"db_findmailbox_by_regex(): not enough memory\n");
@@ -1689,7 +1689,7 @@ int db_findmailbox_by_regex(unsigned long ownerid, const char *pattern,
if (*nchildren == 0)
{
- free(tmp);
+ my_free(tmp);
return 0;
}
@@ -1698,7 +1698,7 @@ int db_findmailbox_by_regex(unsigned long ownerid, const char *pattern,
if (!(*children))
{
trace(TRACE_ERROR,"db_findmailbox_by_regex(): realloc failed\n");
- free(tmp);
+ my_free(tmp);
return -1;
}
@@ -1722,7 +1722,7 @@ int db_getmailbox(mailbox_t *mb, unsigned long userid)
/* free existing MSN list */
if (mb->seq_list)
{
- free(mb->seq_list);
+ my_free(mb->seq_list);
mb->seq_list = NULL;
}
@@ -1794,7 +1794,7 @@ int db_getmailbox(mailbox_t *mb, unsigned long userid)
mb->exists = mysql_num_rows(res);
/* alloc mem */
- mb->seq_list = (unsigned long*)malloc(sizeof(unsigned long) * mb->exists);
+ mb->seq_list = (unsigned long*)my_malloc(sizeof(unsigned long) * mb->exists);
if (!mb->seq_list)
{
/* out of mem */
@@ -1826,7 +1826,7 @@ int db_getmailbox(mailbox_t *mb, unsigned long userid)
{
trace(TRACE_ERROR, "db_getmailbox(): could not determine highest message ID\n");
- free(mb->seq_list);
+ my_free(mb->seq_list);
mb->seq_list = NULL;
return -1;
@@ -1836,7 +1836,7 @@ int db_getmailbox(mailbox_t *mb, unsigned long userid)
{
trace(TRACE_ERROR,"db_getmailbox(): mysql_store_result failed: %s\n",mysql_error(&conn));
- free(mb->seq_list);
+ my_free(mb->seq_list);
mb->seq_list = NULL;
return -1;
@@ -1956,7 +1956,7 @@ int db_listmailboxchildren(unsigned long uid, unsigned long useridnr,
return 0;
}
- *children = (unsigned long*)malloc(sizeof(unsigned long) * (*nchildren));
+ *children = (unsigned long*)my_malloc(sizeof(unsigned long) * (*nchildren));
if (!(*children))
{
@@ -1973,7 +1973,7 @@ int db_listmailboxchildren(unsigned long uid, unsigned long useridnr,
if (i == *nchildren)
{
/* big fatal */
- free(*children);
+ my_free(*children);
*children = NULL;
*nchildren = 0;
mysql_free_result(res);
@@ -2193,7 +2193,7 @@ int db_expunge(unsigned long uid,unsigned long **msgids,int *nmsgs)
/* now alloc mem */
*nmsgs = mysql_num_rows(res);
- *msgids = (unsigned long *)malloc(sizeof(unsigned long) * (*nmsgs));
+ *msgids = (unsigned long *)my_malloc(sizeof(unsigned long) * (*nmsgs));
if (!(*msgids))
{
/* out of mem */
@@ -2217,7 +2217,7 @@ int db_expunge(unsigned long uid,unsigned long **msgids,int *nmsgs)
if (db_query(query) == -1)
{
trace(TRACE_ERROR, "db_expunge(): could not update messages in mailbox\n");
- free(*msgids);
+ my_free(*msgids);
*nmsgs = 0;
return -1;
}
@@ -2705,7 +2705,7 @@ int db_init_msgfetch(unsigned long uid)
return -1; /* msg should have 1 block at least */
}
- if (!(blklengths = (unsigned long*)malloc(nblocks * sizeof(unsigned long))))
+ if (!(blklengths = (unsigned long*)my_malloc(nblocks * sizeof(unsigned long))))
{
trace(TRACE_ERROR, "db_init_msgfetch(): out of memory\n");
mysql_free_result(_msg_result);
@@ -2723,7 +2723,7 @@ int db_init_msgfetch(unsigned long uid)
if (db_query(query) == -1)
{
trace(TRACE_ERROR, "db_init_msgfetch(): could not get message\n");
- free(blklengths);
+ my_free(blklengths);
blklengths = NULL;
return (-1);
}
@@ -2732,7 +2732,7 @@ int db_init_msgfetch(unsigned long uid)
{
trace(TRACE_ERROR,"db_init_msgfetch(): mysql_store_result failed: %s\n",
mysql_error(&conn));
- free(blklengths);
+ my_free(blklengths);
blklengths = NULL;
return (-1);
}
@@ -2891,7 +2891,7 @@ void db_close_msgfetch()
if (!_msg_fetch_inited)
return; /* nothing to be done */
- free(blklengths);
+ my_free(blklengths);
blklengths = NULL;
nblocks = 0;
@@ -3192,7 +3192,7 @@ int db_start_msg(mime_message_t *msg, char *stopbound, int *level, int maxlevel)
}
len = newbound - bptr;
- if (!(newbound = (char*)malloc(len+1)))
+ if (!(newbound = (char*)my_malloc(len+1)))
{
trace(TRACE_ERROR, "db_start_msg(): out of memory\n");
return -3;
@@ -3207,7 +3207,7 @@ int db_start_msg(mime_message_t *msg, char *stopbound, int *level, int maxlevel)
if (db_update_msgbuf(MSGBUF_FORCE_UPDATE) == -1)
{
trace(TRACE_ERROR, "db_startmsg(): error updating msgbuf\n");
- free(newbound);
+ my_free(newbound);
return -2;
}
@@ -3225,7 +3225,7 @@ int db_start_msg(mime_message_t *msg, char *stopbound, int *level, int maxlevel)
if (!msgbuf[msgidx])
{
trace(TRACE_ERROR, "db_start_msg(): unexpected end-of-data\n");
- free(newbound);
+ my_free(newbound);
return -1;
}
@@ -3238,7 +3238,7 @@ int db_start_msg(mime_message_t *msg, char *stopbound, int *level, int maxlevel)
if ((nlines = db_add_mime_children(&msg->children, newbound, level, maxlevel)) < 0)
{
trace(TRACE_ERROR, "db_start_msg(): error adding MIME-children\n");
- free(newbound);
+ my_free(newbound);
return nlines;
}
(*level)--;
@@ -3251,7 +3251,7 @@ int db_start_msg(mime_message_t *msg, char *stopbound, int *level, int maxlevel)
msgidx += (2+sblen); /* double hyphen preceeds */
}
- free(newbound);
+ my_free(newbound);
newbound = NULL;
if (msgidx > 0)
@@ -3384,6 +3384,7 @@ int db_add_mime_children(struct list *brothers, char *splitbound, int *level, in
if ((nlines = mime_readheader(&msgbuf[msgidx], &msgidx, &part.mimeheader, &dummy)) < 0)
{
trace(TRACE_ERROR,"db_add_mime_children(): error reading MIME-header\n");
+ db_free_msg(&part);
return nlines; /* error reading header */
}
totallines += nlines;
@@ -3399,6 +3400,7 @@ int db_add_mime_children(struct list *brothers, char *splitbound, int *level, in
if ((nlines = db_start_msg(&part, splitbound, level, maxlevel)) < 0)
{
trace(TRACE_ERROR,"db_add_mime_children(): error retrieving message\n");
+ db_free_msg(&part);
return nlines;
}
trace(TRACE_DEBUG,"db_add_mime_children(): got %d newlines from start_msg()\n",nlines);
@@ -3418,6 +3420,7 @@ int db_add_mime_children(struct list *brothers, char *splitbound, int *level, in
if (!bptr)
{
trace(TRACE_ERROR, "db_add_mime_children(): could not find a new msg-boundary\n");
+ db_free_msg(&part);
return -1; /* no new boundary ??? */
}
@@ -3435,9 +3438,10 @@ int db_add_mime_children(struct list *brothers, char *splitbound, int *level, in
}
len = newbound - bptr;
- if (!(newbound = (char*)malloc(len+1)))
+ if (!(newbound = (char*)my_malloc(len+1)))
{
trace(TRACE_ERROR, "db_add_mime_children(): out of memory\n");
+ db_free_msg(&part);
return -3;
}
@@ -3452,7 +3456,8 @@ int db_add_mime_children(struct list *brothers, char *splitbound, int *level, in
if (db_update_msgbuf(MSGBUF_FORCE_UPDATE) == -1)
{
trace(TRACE_ERROR, "db_add_mime_children(): error updating msgbuf\n");
- free(newbound);
+ db_free_msg(&part);
+ my_free(newbound);
return -2;
}
@@ -3473,7 +3478,8 @@ int db_add_mime_children(struct list *brothers, char *splitbound, int *level, in
if (!msgbuf[msgidx])
{
trace(TRACE_ERROR, "db_add_mime_children(): unexpected end-of-data\n");
- free(newbound);
+ my_free(newbound);
+ db_free_msg(&part);
return -1;
}
@@ -3487,12 +3493,13 @@ int db_add_mime_children(struct list *brothers, char *splitbound, int *level, in
if ((nlines = db_add_mime_children(&part.children, newbound, level, maxlevel)) < 0)
{
trace(TRACE_ERROR, "db_add_mime_children(): error adding mime children\n");
- free(newbound);
+ my_free(newbound);
+ db_free_msg(&part);
return nlines;
}
(*level)--;
- free(newbound);
+ my_free(newbound);
newbound = NULL;
msgidx += sblen+2; /* skip splitbound */
@@ -3521,7 +3528,10 @@ int db_add_mime_children(struct list *brothers, char *splitbound, int *level, in
while (msgbuf[msgidx])
{
if (db_update_msgbuf(sblen+3) == -1)
- return -2;
+ {
+ db_free_msg(&part);
+ return -2;
+ }
if (msgbuf[msgidx] == '\n')
part.bodylines++;
@@ -3543,6 +3553,7 @@ int db_add_mime_children(struct list *brothers, char *splitbound, int *level, in
if (!msgbuf[msgidx])
{
trace(TRACE_ERROR,"db_add_mime_children(): unexpected end of data\n");
+ db_free_msg(&part);
return -1; /* ?? splitbound should follow */
}
@@ -3558,6 +3569,7 @@ int db_add_mime_children(struct list *brothers, char *splitbound, int *level, in
if (list_nodeadd(brothers, &part, sizeof(part)) == NULL)
{
trace(TRACE_ERROR,"db_add_mime_children(): could not add node\n");
+ db_free_msg(&part);
return -3;
}
@@ -3684,7 +3696,7 @@ int db_msgdump(mime_message_t *msg, unsigned long msguid, int level)
return 0;
}
- spaces = (char*)malloc(3*level + 1);
+ spaces = (char*)my_malloc(3*level + 1);
if (!spaces)
return 0;
@@ -3746,7 +3758,7 @@ int db_msgdump(mime_message_t *msg, unsigned long msguid, int level)
}
trace(TRACE_DEBUG,"%s*** child list end\n",spaces);
- free(spaces);
+ my_free(spaces);
return size;
}
@@ -4324,7 +4336,7 @@ int db_search_messages(char **search_keys, unsigned long **search_results, int *
return 0;
}
- *search_results = (unsigned long*)malloc(sizeof(unsigned long) * *nsresults);
+ *search_results = (unsigned long*)my_malloc(sizeof(unsigned long) * *nsresults);
if (!*search_results)
{
trace(TRACE_ERROR, "db_search_messages(): out of memory\n");
diff --git a/debug.c b/debug.c
index f3d4bfba..5fa7b79e 100644
--- a/debug.c
+++ b/debug.c
@@ -3,7 +3,22 @@
*
* Debugging and memory checking functions */
+#include <stdlib.h>
#include "debug.h"
+#include <string.h>
+
+struct debug_mem
+{
+ long addr;
+ int linenr;
+ char fname[200];
+
+ struct debug_mem *nextaddr;
+};
+
+typedef struct debug_mem debug_mem_t;
+
+debug_mem_t *__dm_first=0,*__dm_last=0;
#define err_out_stream stderr
#define EXIT_CODE 75
@@ -11,8 +26,7 @@
/* the debug variables */
int TRACE_TO_SYSLOG = 1; /* default: yes */
int TRACE_VERBOSE = 0; /* default: no */
-
-int TRACE_LEVEL = 2; /* default: normal operations */
+int TRACE_LEVEL = 4; /* default: normal operations */
/*
* configure the debug settings
@@ -25,7 +39,7 @@ void configure_debug(int level, int trace_syslog, int trace_verbose)
}
-void func_memtst (char filename[255],int line,int tst)
+void func_memtst (const char *filename,int line,int tst)
{
if (tst)
trace(TRACE_FATAL,"func_memtst(): fatal: %s:%d Memory error, result should not be NULL)",
@@ -70,3 +84,96 @@ void trace (int level, const char *formatstring, ...)
if (level==TRACE_STOP)
exit(EXIT_CODE);
}
+
+void* __debug_malloc(unsigned long size, const char *fname, int linenr)
+{
+ void *ptr = malloc(size);
+ debug_mem_t *new;
+
+ if (!ptr)
+ return NULL;
+
+ new = (debug_mem_t*)malloc(sizeof(debug_mem_t));
+
+ if (!new)
+ {
+ trace(TRACE_WARNING,"__debug_malloc(): could not add malloc to list (call: %s, %d)\n",
+ fname,linenr);
+ return ptr;
+ }
+
+ new->addr = (long)ptr;
+ new->linenr = linenr;
+ strncpy(new->fname, fname, 200);
+ new->fname[199]= 0;
+ new->nextaddr = 0;
+
+ if (!__dm_first)
+ {
+ __dm_first = new;
+ __dm_last = new;
+ }
+ else
+ {
+ __dm_last->nextaddr = new;
+ __dm_last = __dm_last->nextaddr;
+ }
+
+ return ptr;
+}
+
+void __debug_free(void *ptr, const char *fname, int linenr)
+{
+ debug_mem_t *curr = __dm_first,*prev = NULL;
+
+ if (!ptr)
+ return;
+
+ while (curr && curr->addr != (long)ptr)
+ {
+ prev = curr;
+ curr = curr->nextaddr;
+ }
+
+ if (!curr)
+ {
+ trace(TRACE_WARNING,"__debug_free(): freeing a memory block that is not in the list\n");
+ trace(TRACE_WARNING,"__debug_free(): called in file %s, line %d\n",fname,linenr);
+ free(ptr);
+ return;
+ }
+
+ if (prev)
+ {
+ prev->nextaddr = curr->nextaddr;
+ if (__dm_last == curr)
+ __dm_last = prev;
+ }
+ else
+ {
+ __dm_first = __dm_first->nextaddr;
+ if (__dm_last == __dm_first)
+ __dm_last = 0;
+ }
+
+ free(curr);
+ free(ptr);
+}
+
+void __debug_dumpallocs()
+{
+ debug_mem_t *curr = __dm_first;
+
+ trace(TRACE_WARNING,"__debug_dumpallocs(): retrieving list of currently allocated items\n");
+
+ while (curr)
+ {
+ trace(TRACE_WARNING," From %s, line %d: %X\n",curr->fname,curr->linenr,curr);
+ curr=curr->nextaddr;
+ }
+
+ trace(TRACE_WARNING,"\n__debug_dumpallocs(): end\n");
+}
+
+
+
diff --git a/debug.h b/debug.h
index a23e0d40..a0f0e9c2 100644
--- a/debug.h
+++ b/debug.h
@@ -25,9 +25,16 @@ extern int TRACE_LEVEL; /* 5: maximum debugging */
#define TRACE_DEBUG 5
#define memtst(tstbool) func_memtst (__FILE__,__LINE__,tstbool)
+#define my_malloc(s) __debug_malloc(s, __FILE__, __LINE__)
+#define my_free(p) __debug_free(p, __FILE__, __LINE__)
-void func_memtst (char filename[255],int line,int tst);
+void func_memtst (const char *filename,int line,int tst);
void trace (int level, const char *formatstring, ...);
void configure_debug(int level, int trace_syslog, int trace_verbose);
+void* __debug_malloc(unsigned long size, const char *fname, int linenr);
+void __debug_free(void *ptr, const char *fname, int linenr);
+
+void __debug_dumpallocs();
+
#endif
diff --git a/imap4.c b/imap4.c
index 7887cdfe..c04eb8a6 100644
--- a/imap4.c
+++ b/imap4.c
@@ -20,7 +20,7 @@
#define MAX_LINESIZE 1024
-#define null_free(p) { free(p); p = NULL; }
+#define null_free(p) { my_free(p); p = NULL; }
/* cache */
cache_t cached_msg;
@@ -85,7 +85,7 @@ int imap_login(ClientInfo *ci)
setlinebuf(ci->tx);
*/
/* add userdata */
- ci->userData = malloc(sizeof(imap_userdata_t));
+ ci->userData = my_malloc(sizeof(imap_userdata_t));
if (!ci->userData)
{
/* out of mem */
@@ -277,7 +277,7 @@ int imap_process(ClientInfo *ci)
/* free used memory */
for (i=0; args[i]; i++)
{
- free(args[i]);
+ my_free(args[i]);
args[i] = NULL;
}
@@ -306,7 +306,7 @@ int imap_process(ClientInfo *ci)
for (i=0; args[i]; i++)
{
- free(args[i]);
+ my_free(args[i]);
args[i] = NULL;
}
@@ -322,7 +322,7 @@ int imap_process(ClientInfo *ci)
if (newmailbox.recent != ud->mailbox.recent)
fprintf(ci->tx, "* %d RECENT\r\n", newmailbox.recent);
- free(ud->mailbox.seq_list);
+ my_free(ud->mailbox.seq_list);
memcpy(&ud->mailbox, &newmailbox, sizeof(newmailbox));
}
@@ -343,7 +343,7 @@ int imap_process(ClientInfo *ci)
for (i=0; args[i]; i++)
{
- free(args[i]);
+ my_free(args[i]);
args[i] = NULL;
}
@@ -359,6 +359,8 @@ int imap_process(ClientInfo *ci)
fprintf(ci->tx,"%s OK completed\r\n",tag);
trace(TRACE_MESSAGE,"IMAPD: Closing connection for client from IP [%s]\n",ci->ip);
+ __debug_dumpallocs();
+
return EOF;
}
diff --git a/imapcommands.c b/imapcommands.c
index 1b213454..f4b65ca3 100644
--- a/imapcommands.c
+++ b/imapcommands.c
@@ -7,7 +7,6 @@
*/
#include "imapcommands.h"
-#include "debug.h"
#include "imaputil.h"
#include "dbmysql.h"
#include <string.h>
@@ -16,6 +15,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <time.h>
+#include "debug.h"
#ifndef MAX_LINESIZE
#define MAX_LINESIZE 1024
@@ -538,7 +538,7 @@ int _ic_create(char *tag, char **args, ClientInfo *ci)
}
/* alloc a ptr which can contain up to the full name */
- cpy = (char*)malloc(sizeof(char) * (strlen(args[0]) + 1));
+ cpy = (char*)my_malloc(sizeof(char) * (strlen(args[0]) + 1));
if (!cpy)
{
/* out of mem */
@@ -555,7 +555,7 @@ int _ic_create(char *tag, char **args, ClientInfo *ci)
/* serious error while making chunks */
trace(TRACE_ERROR, "IMAPD: create(): could not create chunks\r\n");
fprintf(ci->tx, "%s BYE server ran out of memory\r\n",tag);
- free(cpy);
+ my_free(cpy);
return -1;
}
@@ -564,7 +564,7 @@ int _ic_create(char *tag, char **args, ClientInfo *ci)
/* wrong argument */
fprintf(ci->tx,"%s NO invalid mailbox name specified\r\n",tag);
free_chunks(chunks);
- free(cpy);
+ my_free(cpy);
return 1;
}
@@ -578,7 +578,7 @@ int _ic_create(char *tag, char **args, ClientInfo *ci)
/* no can do */
fprintf(ci->tx, "%s NO invalid mailbox name specified\r\n",tag);
free_chunks(chunks);
- free(cpy);
+ my_free(cpy);
return 1;
}
@@ -605,7 +605,7 @@ int _ic_create(char *tag, char **args, ClientInfo *ci)
/* dbase failure */
fprintf(ci->tx,"* BYE internal dbase error\r\n");
free_chunks(chunks);
- free(cpy);
+ my_free(cpy);
return -1; /* fatal */
}
@@ -628,7 +628,7 @@ int _ic_create(char *tag, char **args, ClientInfo *ci)
{
fprintf(ci->tx, "%s NO mailbox cannot have inferior names\r\n",tag);
free_chunks(chunks);
- free(cpy);
+ my_free(cpy);
return 1;
}
@@ -637,7 +637,7 @@ int _ic_create(char *tag, char **args, ClientInfo *ci)
/* dbase failure */
fprintf(ci->tx,"* BYE internal dbase error\r\n");
free_chunks(chunks);
- free(cpy);
+ my_free(cpy);
return -1; /* fatal */
}
}
@@ -645,7 +645,7 @@ int _ic_create(char *tag, char **args, ClientInfo *ci)
/* creation complete */
free_chunks(chunks);
- free(cpy);
+ my_free(cpy);
fprintf(ci->tx,"%s OK CREATE completed\r\n",tag);
return 0;
@@ -709,13 +709,13 @@ int _ic_delete(char *tag, char **args, ClientInfo *ci)
if (result == 0)
{
fprintf(ci->tx,"%s NO mailbox is non-selectable\r\n",tag);
- free(children);
+ my_free(children);
return 1;
}
if (result == -1)
{
fprintf(ci->tx,"* BYE internal dbase error\r\n");
- free(children);
+ my_free(children);
return -1; /* fatal */
}
@@ -727,13 +727,13 @@ int _ic_delete(char *tag, char **args, ClientInfo *ci)
if (result == -1)
{
fprintf(ci->tx,"* BYE internal dbase error\r\n");
- free(children);
+ my_free(children);
return -1; /* fatal */
}
/* ok done */
fprintf(ci->tx,"%s OK DELETE completed\r\n",tag);
- free(children);
+ my_free(children);
return 0;
}
@@ -880,7 +880,7 @@ int _ic_rename(char *tag, char **args, ClientInfo *ci)
if (result == -1)
{
fprintf(ci->tx,"* BYE internal dbase error\r\n");
- free(children);
+ my_free(children);
return -1;
}
@@ -889,7 +889,7 @@ int _ic_rename(char *tag, char **args, ClientInfo *ci)
/* strange error, let's say its fatal */
trace(TRACE_ERROR,"IMAPD: rename(): mailbox names are fucked up\r\n");
fprintf(ci->tx,"* BYE internal error regarding mailbox names\r\n");
- free(children);
+ my_free(children);
return -1;
}
@@ -899,12 +899,12 @@ int _ic_rename(char *tag, char **args, ClientInfo *ci)
if (result == -1)
{
fprintf(ci->tx,"* BYE internal dbase error\r\n");
- free(children);
+ my_free(children);
return -1;
}
}
if (children)
- free(children);
+ my_free(children);
/* now replace name */
result = db_setmailboxname(mboxid, args[1]);
@@ -1035,7 +1035,7 @@ int _ic_list(char *tag, char **args, ClientInfo *ci)
}
plen = strlen(args[1]) * 6;
- pattern = (char*)malloc(sizeof(char) * (plen + slen + 10)); /* +10 for some xtra space */
+ pattern = (char*)my_malloc(sizeof(char) * (plen + slen + 10)); /* +10 for some xtra space */
if (!pattern)
{
fprintf(ci->tx,"* BYE out of memory\r\n");
@@ -1075,16 +1075,16 @@ int _ic_list(char *tag, char **args, ClientInfo *ci)
if (result == -1)
{
fprintf(ci->tx,"* BYE internal dbase error\r\n");
- free(children);
- free(pattern);
+ my_free(children);
+ my_free(pattern);
return -1;
}
if (result == 1)
{
fprintf(ci->tx,"%s BAD invalid pattern specified\r\n",tag);
- free(children);
- free(pattern);
+ my_free(children);
+ my_free(pattern);
return 1;
}
@@ -1096,8 +1096,8 @@ int _ic_list(char *tag, char **args, ClientInfo *ci)
if (result == -1)
{
fprintf(ci->tx,"* BYE internal dbase error\r\n");
- free(children);
- free(pattern);
+ my_free(children);
+ my_free(pattern);
return -1;
}
@@ -1108,8 +1108,8 @@ int _ic_list(char *tag, char **args, ClientInfo *ci)
if (result == -1)
{
fprintf(ci->tx,"\r\n* BYE internal dbase error\r\n");
- free(children);
- free(pattern);
+ my_free(children);
+ my_free(pattern);
return -1;
}
@@ -1119,8 +1119,8 @@ int _ic_list(char *tag, char **args, ClientInfo *ci)
if (result == -1)
{
fprintf(ci->tx,"\r\n* BYE internal dbase error\r\n");
- free(children);
- free(pattern);
+ my_free(children);
+ my_free(pattern);
return -1;
}
@@ -1131,9 +1131,9 @@ int _ic_list(char *tag, char **args, ClientInfo *ci)
}
if (children)
- free(children);
+ my_free(children);
- free(pattern);
+ my_free(pattern);
fprintf(ci->tx,"%s OK %s completed\r\n",tag,thisname);
return 0;
@@ -1260,7 +1260,7 @@ int _ic_status(char *tag, char **args, ClientInfo *ci)
else
{
fprintf(ci->tx,"\r\n%s BAD unrecognized option '%s' specified\r\n",tag,args[i]);
- free(mb.seq_list);
+ my_free(mb.seq_list);
return 1;
}
}
@@ -1269,7 +1269,7 @@ int _ic_status(char *tag, char **args, ClientInfo *ci)
fprintf(ci->tx,"%s OK STATUS completed\r\n",tag);
- free(mb.seq_list);
+ my_free(mb.seq_list);
return 0;
}
@@ -1367,7 +1367,7 @@ int _ic_append(char *tag, char **args, ClientInfo *ci)
return 1;
}
- msgdata = (char*)malloc((literal_size+1) * sizeof(char));
+ msgdata = (char*)my_malloc((literal_size+1) * sizeof(char));
if (!msgdata)
{
trace(TRACE_ERROR, "ic_append(): not enough memory\n");
@@ -1422,7 +1422,7 @@ int _ic_append(char *tag, char **args, ClientInfo *ci)
break;
}
- free(msgdata);
+ my_free(msgdata);
msgdata = NULL;
return result;
@@ -1513,7 +1513,7 @@ int _ic_expunge(char *tag, char **args, ClientInfo *ci)
fprintf(ci->tx,"* %d EXPUNGE\r\n",idx+1); /* add one: IMAP MSN starts at 1 not zero */
}
- free(msgids);
+ my_free(msgids);
msgids = NULL;
/* update mailbox info */
@@ -1526,7 +1526,7 @@ int _ic_expunge(char *tag, char **args, ClientInfo *ci)
if (result == -1)
{
fprintf(ci->tx,"* BYE internal dbase error\r\n");
- free(newmailbox.seq_list);
+ my_free(newmailbox.seq_list);
return -1; /* fatal */
}
@@ -1536,7 +1536,7 @@ int _ic_expunge(char *tag, char **args, ClientInfo *ci)
if (newmailbox.recent != ud->mailbox.recent)
fprintf(ci->tx, "* %d RECENT\r\n", newmailbox.recent);
- free(ud->mailbox.seq_list);
+ my_free(ud->mailbox.seq_list);
memcpy(&ud->mailbox, &newmailbox, sizeof(newmailbox));
fprintf(ci->tx,"%s OK EXPUNGE completed\r\n",tag);
@@ -1626,7 +1626,7 @@ int _ic_search(char *tag, char **args, ClientInfo *ci)
}
/* allocate memory for result set */
- result_set = (int*)malloc(sizeof(int) * ud->mailbox.exists);
+ result_set = (int*)my_malloc(sizeof(int) * ud->mailbox.exists);
if (!result_set)
{
free_searchlist(&sk.sub_search);
@@ -1647,7 +1647,7 @@ int _ic_search(char *tag, char **args, ClientInfo *ci)
if (result < 0)
{
free_searchlist(&sk.sub_search);
- free(result_set);
+ my_free(result_set);
fprintf(ci->tx,"%s", (result == -1) ?
"* BYE internal dbase error\r\n" :
"* BYE server ran out of memory\r\n");
@@ -1658,7 +1658,7 @@ int _ic_search(char *tag, char **args, ClientInfo *ci)
if (result == 1)
{
- free(result_set);
+ my_free(result_set);
result_set = NULL;
}
@@ -1682,7 +1682,7 @@ int _ic_search(char *tag, char **args, ClientInfo *ci)
}
fprintf(ci->tx,"\r\n");
- free(result_set);
+ my_free(result_set);
fprintf(ci->tx,"%s OK SEARCH completed\r\n",tag);
return 0;
diff --git a/imapd.c b/imapd.c
index fb32beb3..bceda37a 100644
--- a/imapd.c
+++ b/imapd.c
@@ -52,7 +52,7 @@ int main()
if (daem)
{
d = (strcmp(daem, "yes") == 0);
- free(daem);
+ my_free(daem);
daem = NULL;
}
else
@@ -61,28 +61,28 @@ int main()
if (to)
{
timeout = atoi(to);
- free(to);
+ my_free(to);
to = NULL;
}
if (trace_level)
{
new_level = atoi(trace_level);
- free(trace_level);
+ my_free(trace_level);
trace_level = NULL;
}
if (trace_syslog)
{
new_trace_syslog = atoi(trace_syslog);
- free(trace_syslog);
+ my_free(trace_syslog);
trace_syslog = NULL;
}
if (trace_verbose)
{
new_trace_verbose = atoi(trace_verbose);
- free(trace_verbose);
+ my_free(trace_verbose);
trace_verbose = NULL;
}
@@ -92,8 +92,8 @@ int main()
/* open socket */
sock = SS_MakeServerSock(bindip, port, atoi(defchld), timeout);
- free(port);
- free(bindip);
+ my_free(port);
+ my_free(bindip);
port = NULL;
bindip = NULL;
@@ -113,8 +113,8 @@ int main()
if (drop_priviledges (newuser, newgroup) != 0)
trace(TRACE_FATAL,"IMAPD: could not set uid %s, gid %s\n",newuser,newgroup);
- free(newuser);
- free(newgroup);
+ my_free(newuser);
+ my_free(newgroup);
newuser = NULL;
newgroup = NULL;
}
@@ -137,8 +137,8 @@ int main()
SS_CloseServer(sock);
- free(defchld);
- free(maxchld);
+ my_free(defchld);
+ my_free(maxchld);
defchld = NULL;
maxchld = NULL;
diff --git a/imaputil.c b/imaputil.c
index 328a4656..0e1a1005 100644
--- a/imaputil.c
+++ b/imaputil.c
@@ -1079,7 +1079,7 @@ char **give_chunks(const char *str, char delimiter)
int cnt,i;
char **array,*cpy,*tmp;
- cpy = (char*)malloc(sizeof(char) * (strlen(str) + 1));
+ cpy = (char*)my_malloc(sizeof(char) * (strlen(str) + 1));
if (!cpy )
{
trace(TRACE_ERROR, "give_chunks(): out of memory\n");
@@ -1100,12 +1100,12 @@ char **give_chunks(const char *str, char delimiter)
/* alloc mem */
cnt++; /* for NULL termination */
- array = (char**)malloc(sizeof(char*) * cnt);
+ array = (char**)my_malloc(sizeof(char*) * cnt);
if (!array)
{
trace(TRACE_ERROR, "give_chunks(): out of memory\n");
- free(cpy);
+ my_free(cpy);
return NULL;
}
@@ -1137,9 +1137,9 @@ void free_chunks(char **chunks)
return;
if (chunks[0])
- free(chunks[0]); /* the entire array will be freed now */
+ my_free(chunks[0]); /* the entire array will be freed now */
- free(chunks); /* free ptrs to strings */
+ my_free(chunks); /* free ptrs to strings */
}
@@ -1262,12 +1262,12 @@ char **build_args_array(const char *s)
if (inquote)
{
/* quotation end, treat quoted string as argument */
- if (!(the_args[nargs] = (char*)malloc(sizeof(char) * (i-quotestart)) ))
+ if (!(the_args[nargs] = (char*)my_malloc(sizeof(char) * (i-quotestart)) ))
{
/* out of mem */
while (--nargs >= 0)
{
- free(the_args[nargs]);
+ my_free(the_args[nargs]);
the_args[nargs] = NULL;
}
@@ -1334,19 +1334,19 @@ char **build_args_array(const char *s)
/* error in parenthesis structure */
while (--nargs >= 0)
{
- free(the_args[nargs]);
+ my_free(the_args[nargs]);
the_args[nargs] = NULL;
}
return NULL;
}
/* add this parenthesis to the arg list and continue */
- if (!(the_args[nargs] = (char*)malloc( sizeof(" ") )) )
+ if (!(the_args[nargs] = (char*)my_malloc( sizeof(" ") )) )
{
/* out of mem */
while (--nargs >= 0)
{
- free(the_args[nargs]);
+ my_free(the_args[nargs]);
the_args[nargs] = NULL;
}
@@ -1375,12 +1375,12 @@ char **build_args_array(const char *s)
else break;
}
- if (!(the_args[nargs] = (char*)malloc(sizeof(char) * (i-argstart +1)) ))
+ if (!(the_args[nargs] = (char*)my_malloc(sizeof(char) * (i-argstart +1)) ))
{
/* out of mem */
while (--nargs >= 0)
{
- free(the_args[nargs]);
+ my_free(the_args[nargs]);
the_args[nargs] = NULL;
}
@@ -1401,7 +1401,7 @@ char **build_args_array(const char *s)
/* error in parenthesis structure */
while (--nargs >= 0)
{
- free(the_args[nargs]);
+ my_free(the_args[nargs]);
the_args[nargs] = NULL;
}
return NULL;
@@ -2394,7 +2394,7 @@ int perform_imap_search(int *rset, int setlen, search_key_t *sk, mailbox_t *mb)
if (!sk)
return 0; /* no search */
- newset = (int*)malloc(sizeof(int) * setlen);
+ newset = (int*)my_malloc(sizeof(int) * setlen);
if (!newset)
return -2;
@@ -2412,7 +2412,7 @@ int perform_imap_search(int *rset, int setlen, search_key_t *sk, mailbox_t *mb)
result = db_search(rset, setlen, sk->search, mb);
if (result != 0)
{
- free(newset);
+ my_free(newset);
return result;
}
break;
@@ -2435,7 +2435,7 @@ int perform_imap_search(int *rset, int setlen, search_key_t *sk, mailbox_t *mb)
result = db_search(rset, setlen, sk->search, mb);
if (result != 0)
{
- free(newset);
+ my_free(newset);
return result;
}
break;
@@ -2459,7 +2459,7 @@ int perform_imap_search(int *rset, int setlen, search_key_t *sk, mailbox_t *mb)
result = perform_imap_search(newset, setlen, subsk, mb);
if (result < 0 || result == 1)
{
- free(newset);
+ my_free(newset);
return result;
}
@@ -2474,11 +2474,11 @@ int perform_imap_search(int *rset, int setlen, search_key_t *sk, mailbox_t *mb)
break;
default:
- free(newset);
+ my_free(newset);
return -2; /* ??? */
}
- free(newset);
+ my_free(newset);
return 0;
}
@@ -2734,7 +2734,7 @@ void build_uid_set(int *set, int setlen, char *cset, mailbox_t *mb)
void dumpsearch(search_key_t *sk, int level)
{
- char *spaces = (char*)malloc(level*3 +1);
+ char *spaces = (char*)my_malloc(level*3 +1);
struct element *el;
search_key_t *subsk;
@@ -2747,7 +2747,7 @@ void dumpsearch(search_key_t *sk, int level)
if (!sk)
{
trace(TRACE_DEBUG,"%s(null)\n",spaces);
- free(spaces);
+ my_free(spaces);
return;
}
@@ -2795,7 +2795,7 @@ void dumpsearch(search_key_t *sk, int level)
trace(TRACE_DEBUG,"%s[type %d] \"%s\"\n",spaces,sk->type,sk->search);
}
- free(spaces);
+ my_free(spaces);
return;
}
diff --git a/list.c b/list.c
index 5a1eecd6..33c18da3 100644
--- a/list.c
+++ b/list.c
@@ -9,8 +9,6 @@
#include "debug.h"
#include "list.h"
-extern void func_memtst (char filename[255],int line,int tst);
-
void list_init(struct list *tlist)
{
tlist->start=NULL;
@@ -33,8 +31,8 @@ void list_freelist(struct element **start)
list_freelist(&(*start)->nextnode);
/* free this item */
- free((*start)->data);
- free(*start);
+ my_free((*start)->data);
+ my_free(*start);
*start = NULL;
}
@@ -81,20 +79,20 @@ struct element *list_nodeadd(struct list *tlist, void *data,
p=tlist->start;
- tlist->start=(struct element *)malloc(sizeof(struct element));
+ tlist->start=(struct element *)my_malloc(sizeof(struct element));
/* allocating memory */
#ifdef USE_EXIT_ON_ERROR
memtst(tlist->start==NULL);
- memtst((tlist->start->data=(void *)malloc(dsize))==NULL);
+ memtst((tlist->start->data=(void *)my_malloc(dsize))==NULL);
#else
if (!tlist->start)
return NULL;
- tlist->start->data=(void *)malloc(dsize);
+ tlist->start->data=(void *)my_malloc(dsize);
if (!tlist->start->data)
{
- free(tlist->start);
+ my_free(tlist->start);
tlist->start = NULL;
return NULL;
}
@@ -169,7 +167,7 @@ struct element *list_nodedel(struct list *tlist,void *data)
else
{
item->nextnode=temp->nextnode;
- free(temp->data); /* freeing memory */
+ my_free(temp->data); /* freeing memory */
free ((struct element *)temp);
break;
}
diff --git a/mime.c b/mime.c
index 709e3a07..f8ff3679 100644
--- a/mime.c
+++ b/mime.c
@@ -37,9 +37,9 @@ int mime_list(char *blkdata, struct list *mimelist)
list_init(mimelist);
/* alloc mem */
#ifdef USE_EXIT_ON_ERROR
- memtst((mr=(struct mime_record *)malloc(sizeof(struct mime_record)))==NULL);
+ memtst((mr=(struct mime_record *)my_malloc(sizeof(struct mime_record)))==NULL);
#else
- mr=(struct mime_record *)malloc(sizeof(struct mime_record));
+ mr=(struct mime_record *)my_malloc(sizeof(struct mime_record));
if (!mr)
{
@@ -73,7 +73,7 @@ int mime_list(char *blkdata, struct list *mimelist)
if (!(*endptr))
{
/* end of data block reached */
- free(mr);
+ my_free(mr);
return 0;
}
@@ -112,7 +112,7 @@ int mime_list(char *blkdata, struct list *mimelist)
if (!el)
{
trace(TRACE_ERROR, "mime_list(): cannot add element to list\n");
- free(mr);
+ my_free(mr);
return -1;
}
#endif
@@ -124,14 +124,14 @@ int mime_list(char *blkdata, struct list *mimelist)
if (*startptr == '\n')
{
/* end of header: double newline */
- free(mr);
+ my_free(mr);
return 0;
}
}
else
{
/* no field/value delimiter found, non-valid MIME-header */
- free(mr);
+ my_free(mr);
trace(TRACE_ERROR,"Non valid mimeheader found, freeing list...\n");
list_freelist(&mimelist->start);
mimelist->total_nodes = 0;
@@ -141,13 +141,13 @@ int mime_list(char *blkdata, struct list *mimelist)
}
}
- free(mr); /* no longer need this */
+ my_free(mr); /* no longer need this */
trace(TRACE_DEBUG,"mime_list(): mimeloop finished\n");
if (valid_mime_lines < 2)
{
#ifdef USE_EXIT_ON_ERROR
- free(blkdata);
+ my_free(blkdata);
trace(TRACE_STOP,"mime_list(): no valid mime headers found");
#else
trace(TRACE_ERROR,"mime_list(): no valid mime headers found\n");
@@ -202,7 +202,7 @@ int mime_readheader(char *blkdata, unsigned long *blkidx, struct list *mimelist,
}
/* alloc mem */
- mr=(struct mime_record *)malloc(sizeof(struct mime_record));
+ mr=(struct mime_record *)my_malloc(sizeof(struct mime_record));
if (!mr)
{
@@ -231,7 +231,7 @@ int mime_readheader(char *blkdata, unsigned long *blkidx, struct list *mimelist,
if (!(*endptr))
{
/* end of data block reached (??) */
- free(mr);
+ my_free(mr);
*blkidx += (endptr-startptr);
return totallines;
@@ -302,7 +302,7 @@ int mime_readheader(char *blkdata, unsigned long *blkidx, struct list *mimelist,
if (!el)
{
trace(TRACE_ERROR, "mime_readheader(): cannot add element to list\n");
- free(mr);
+ my_free(mr);
return -2;
}
@@ -346,7 +346,7 @@ int mime_readheader(char *blkdata, unsigned long *blkidx, struct list *mimelist,
if (!el)
{
trace(TRACE_ERROR, "mime_readheader(): cannot add element to list\n");
- free(mr);
+ my_free(mr);
return -2;
}
}
@@ -385,7 +385,7 @@ int mime_readheader(char *blkdata, unsigned long *blkidx, struct list *mimelist,
(*headersize)+=2;
trace(TRACE_DEBUG,"mime_readheader(): found double newline; header size: %d lines\n",
totallines);
- free(mr);
+ my_free(mr);
return totallines;
}
@@ -393,7 +393,7 @@ int mime_readheader(char *blkdata, unsigned long *blkidx, struct list *mimelist,
/* everything down here should be unreachable */
- free(mr); /* no longer need this */
+ my_free(mr); /* no longer need this */
trace(TRACE_DEBUG,"mime_readheader(): mimeloop finished\n");
if (valid_mime_lines < 2)
@@ -520,7 +520,7 @@ int mail_adr_list(char *scan_for_field, struct list *targetlist, struct list *mi
raw=raw->nextnode;
}
- free(tmpvalue);
+ my_free(tmpvalue);
trace (TRACE_DEBUG,"mail_adr_list(): found %d emailaddresses",list_totalnodes(targetlist));