diff --git a/libclamav/mbox.c b/libclamav/mbox.c index 34e64874b..8cfb988e0 100644 --- a/libclamav/mbox.c +++ b/libclamav/mbox.c @@ -2365,7 +2365,7 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re * bother saving to scan, it's safe */ saveIt = (bool)(encodingLine(mainMessage) != NULL); - else if((t_line = encodingLine(mainMessage)) != NULL) { + else if(mainMessage->body_last != NULL && (t_line = encodingLine(mainMessage)) != NULL) { /* * Some bounces include the message * body without the headers. diff --git a/libclamav/message.c b/libclamav/message.c index 22d4b8b34..297ba9c76 100644 --- a/libclamav/message.c +++ b/libclamav/message.c @@ -1075,8 +1075,10 @@ messageMoveText(message *m, text *t, message *old_message) for(u = old_message->body_first; u != t;) { text *next; - if(u->t_line) + if(u->t_line) { lineUnlink(u->t_line); + u->t_line = NULL; + } next = u->t_next; free(u); diff --git a/libclamav/text.c b/libclamav/text.c index 5c6e7ea13..7d3c3a66f 100644 --- a/libclamav/text.c +++ b/libclamav/text.c @@ -124,8 +124,10 @@ textDestroy(text *t_head) { while(t_head) { text *t_next = t_head->t_next; - if(t_head->t_line) - (void)lineUnlink(t_head->t_line); + if(t_head->t_line) { + lineUnlink(t_head->t_line); + t_head->t_line = NULL; + } free(t_head); t_head = t_next; } @@ -146,12 +148,14 @@ textCopy(const text *t_head) } if(last == NULL) { - cli_errmsg("textCopy: Unable to allocate memory to clone object\n"); + cli_errmsg("textCopy: Unable to allocate memory to clone object\n"); if(first) textDestroy(first); return NULL; } + last->t_next = NULL; + if(t_head->t_line) last->t_line = lineLink(t_head->t_line); else