]> 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 42cfee005465f40594aa9bda1937b1288738e029..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,6 +117,10 @@ 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");
@@ -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,18 +158,13 @@ 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.
@@ -189,6 +190,8 @@ int clamd(struct CtdlMessage *msg) {
        }
 
 bail:  close(sock);
+       FreeStrBuf(&CCC->sReadBuf);
+       FreeStrBuf(&CCC->sMigrateBuf);
        return(is_virus);
 }