]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/clamav/serv_virus.c
* migrate redirect_buffer logic to StrBuf, valgrind reported some related errors.
[citadel.git] / citadel / modules / clamav / serv_virus.c
index 6aeeaa9bf3819a2654ee9085b890e634018ede97..1553498921dc7331e5c598f6fd52086b88fa7b7a 100644 (file)
@@ -83,8 +83,8 @@ int clamd(struct CtdlMessage *msg) {
         char portbuf[SIZ];
        int is_virus = 0;
        int clamhost;
-       char *msgtext;
-       size_t msglen;
+       StrBuf *msgtext;
+       CitContext *CCC;
 
        /* Don't care if you're logged in.  You can still spread viruses.
         */
@@ -117,11 +117,15 @@ int clamd(struct CtdlMessage *msg) {
                 */
                return(0);
        }
+       CCC=CC;
+       CCC->sReadBuf = NewStrBuf();
+       CCC->sMigrateBuf = NewStrBuf();
+       CCC->sPos = NULL;
 
        /* Command */
        CtdlLogPrintf(CTDL_DEBUG, "Transmitting STREAM command\n");
        sprintf(buf, "STREAM\r\n");
-       sock_write(sock, buf, strlen(buf));
+       sock_write(&sock, buf, strlen(buf));
 
        CtdlLogPrintf(CTDL_DEBUG, "Waiting for PORT number\n");
         if (sock_getln(&sock, buf, sizeof buf) < 0) {
@@ -143,6 +147,8 @@ int clamd(struct CtdlMessage *msg) {
                /* If the service isn't running, just pass the mail
                 * through.  Potentially throwing away mails isn't good.
                 */
+               FreeStrBuf(&CCC->sReadBuf);
+               FreeStrBuf(&CCC->sMigrateBuf);
                return(0);
         }
        else {
@@ -152,23 +158,19 @@ int clamd(struct CtdlMessage *msg) {
 
 
        /* Message */
-       CC->redirect_buffer = malloc(SIZ);
-       CC->redirect_len = 0;
-       CC->redirect_alloc = SIZ;
+       CC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
        CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1, 0);
        msgtext = CC->redirect_buffer;
-       msglen = CC->redirect_len;
        CC->redirect_buffer = NULL;
-       CC->redirect_len = 0;
-       CC->redirect_alloc = 0;
 
-       sock_write(streamsock, msgtext, msglen);
-       free(msgtext);
+       sock_write(&streamsock, SKEY(msgtext));
+       FreeStrBuf(&msgtext);
 
        /* Close the streamsocket connection; this tells clamd
         * that we're done.
         */
-       close(streamsock);
+       if (streamsock != -1)
+               close(streamsock);
        
        /* Response */
        CtdlLogPrintf(CTDL_DEBUG, "Awaiting response\n");
@@ -188,6 +190,8 @@ int clamd(struct CtdlMessage *msg) {
        }
 
 bail:  close(sock);
+       FreeStrBuf(&CCC->sReadBuf);
+       FreeStrBuf(&CCC->sMigrateBuf);
        return(is_virus);
 }