SMTP-Client: another possible NULL-Pointer access.
[citadel.git] / citadel / modules / smtp / serv_smtpeventclient.c
index 0d3428fea894f5ed529b75e2b50254875ad2064d..5cf7e7e4a748b4c032313118d00f763d808c2a28 100644 (file)
@@ -203,14 +203,16 @@ eNextState FinalizeMessageSend_DB(AsyncIO *IO)
        }
 
        RemoveContext(Msg->IO.CitContext);
-       if (Msg->IDestructQueItem)
-               RemoveQItem(Msg->MyQItem);
        return eAbort;
 }
 
 eNextState Terminate(AsyncIO *IO)
 {
        SmtpOutMsg *Msg = IO->Data;
+
+       if (Msg->IDestructQueItem)
+               RemoveQItem(Msg->MyQItem);
+
        DeleteSmtpOutMsg(Msg);
        return eAbort;
 }
@@ -528,6 +530,8 @@ SmtpOutMsg *new_smtp_outmsg(OneQueItem *MyQItem,
        SmtpOutMsg * Msg;
 
        Msg = (SmtpOutMsg *) malloc(sizeof(SmtpOutMsg));
+       if (Msg == NULL)
+               return NULL;
        memset(Msg, 0, sizeof(SmtpOutMsg));
 
        Msg->n                = MsgCount;
@@ -565,6 +569,12 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem,
        SMTPC_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
 
        Msg = new_smtp_outmsg(MyQItem, MyQEntry, MsgCount);
+       if (Msg == NULL) {
+               SMTPC_syslog(LOG_DEBUG, "%s Failed to alocate message context.\n", __FUNCTION__);
+               if (KeepMsgText) 
+                       FreeStrBuf (&MsgText);
+               return;
+       }
        if (KeepMsgText) Msg->msgtext = MsgText;
        else             Msg->msgtext = NewStrBufDup(MsgText);
 
@@ -598,8 +608,7 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem,
        }
        else {
                /* No recipients? well fail then. */
-               if ((Msg==NULL) ||
-                   (Msg->MyQEntry == NULL)) {
+               if (Msg->MyQEntry != NULL) {
                        Msg->MyQEntry->Status = 5;
                        StrBufPlain(Msg->MyQEntry->StatusMessage,
                                    HKEY("Invalid Recipient!"));