* Minor fixenbugs after running with Valgrind
authorArt Cancro <ajc@citadel.org>
Wed, 19 Jan 2005 20:49:46 +0000 (20:49 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 19 Jan 2005 20:49:46 +0000 (20:49 +0000)
citadel/ChangeLog
citadel/database_sleepycat.c
citadel/imap_fetch.c
citadel/msgbase.c
citadel/serv_calendar.c
citadel/serv_network.c
citadel/serv_smtp.c
citadel/sysdep.c
citadel/tools.c

index 24049771ea8565ade32855f26bc3eb5affb4b6be..3b21ad9dab863b05a63eae95d593e4c0cd5ce798 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 629.8  2005/01/19 20:49:46  ajc
+ * Minor fixenbugs after running with Valgrind
+
  Revision 629.7  2005/01/19 03:03:36  ajc
  * Minor and/or cosmetic changes made during x64 troubleshooting
 
@@ -6280,3 +6283,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index b2b2a691f17556b70592d94b308b0e738b9277c9..9b1b740f33ad905d52f95a7d3518a97daa8005d6 100644 (file)
@@ -366,8 +366,7 @@ void open_databases(void)
                                dbfilename,
                                NULL,
                                DB_BTREE,
-                               DB_CREATE|DB_THREAD
-                               |DB_AUTO_COMMIT
+                               DB_CREATE|DB_AUTO_COMMIT|DB_THREAD
                                ,
                                0600);
                if (ret) {
index 86088b79c3865be51237f1bb725518e6347dd31d..1672e6e5d0dff2b6b1f87dcbec78f4c2d6efc704 100644 (file)
@@ -156,13 +156,9 @@ void imap_fetch_rfc822(long msgnum, char *whichfmt) {
                 * Load the message into a temp file for translation
                 * and measurement
                 */
-               TRACE;
                CtdlRedirectOutput(tmp, -1);
-               TRACE;
                CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
-               TRACE;
                CtdlRedirectOutput(NULL, -1);
-               TRACE;
 
                IMAP->cached_fetch = tmp;
                IMAP->cached_msgnum = msgnum;
@@ -581,37 +577,28 @@ void imap_fetch_body(long msgnum, char *item, int is_peek) {
                        return;
                }
                msg = CtdlFetchMessage(msgnum, 1);
-TRACE;
        }
 
        /* Now figure out what the client wants, and get it */
-TRACE;
 
        if (IMAP->cached_body != NULL) {
                tmp = IMAP->cached_body;
-TRACE;
        }
        else if ( (!strcmp(section, "1")) && (msg->cm_format_type != 4) ) {
-TRACE;
                CtdlRedirectOutput(tmp, -1);
                CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
                                                HEADERS_NONE, 0, 1);
                CtdlRedirectOutput(NULL, -1);
-TRACE;
        }
 
        else if (!strcmp(section, "")) {
-TRACE;
                CtdlRedirectOutput(tmp, -1);
-TRACE;
                lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n");
                lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") );
                lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum);
                CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
                                                HEADERS_ALL, 0, 1);
-TRACE;
                CtdlRedirectOutput(NULL, -1);
-TRACE;
        }
 
        /*
@@ -619,15 +606,12 @@ TRACE;
         * fields, strip it down.
         */
        else if (!strncasecmp(section, "HEADER", 6)) {
-TRACE;
                CtdlRedirectOutput(tmp, -1);
-TRACE;
                lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n");
                lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") );
                lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum);
                CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
                                                HEADERS_ONLY, 0, 1);
-TRACE;
                CtdlRedirectOutput(NULL, -1);
                imap_strip_headers(tmp, section);
        }
@@ -642,9 +626,7 @@ TRACE;
                lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum);
                CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822,
                                                HEADERS_NONE, 0, 1);
-TRACE;
                CtdlRedirectOutput(NULL, -1);
-TRACE;
        }
 
        /*
@@ -652,83 +634,57 @@ TRACE;
         * (Note value of 1 passed as 'dont_decode' so client gets it encoded)
         */
        else {
-TRACE;
                safestrncpy(imfp.desired_section, section,
                                sizeof(imfp.desired_section));
-TRACE;
                imfp.output_fp = tmp;
-TRACE;
 
                mime_parser(msg->cm_fields['M'], NULL,
                                *imap_load_part, NULL, NULL,
                                (void *)&imfp,
                                1);
-TRACE;
        }
 
 
-TRACE;
        fseek(tmp, 0L, SEEK_END);
-TRACE;
        bytes_remaining = ftell(tmp);
-TRACE;
 
        if (is_partial == 0) {
-TRACE;
                rewind(tmp);
                cprintf("BODY[%s] {%ld}\r\n", section, bytes_remaining);
-TRACE;
        }
        else {
-TRACE;
                sscanf(partial, "%ld.%ld", &pstart, &pbytes);
                if ((bytes_remaining - pstart) < pbytes) {
                        pbytes = bytes_remaining - pstart;
                }
-TRACE;
                fseek(tmp, pstart, SEEK_SET);
-TRACE;
                bytes_remaining = pbytes;
-TRACE;
                cprintf("BODY[%s]<%ld> {%ld}\r\n",
                        section, pstart, bytes_remaining);
        }
-TRACE;
 
        blocksize = (long)sizeof(buf);
-TRACE;
        while (bytes_remaining > 0L) {
-TRACE;
                if (blocksize > bytes_remaining) blocksize = bytes_remaining;
-TRACE;
                fread(buf, blocksize, 1, tmp);
-TRACE;
                client_write(buf, (int)blocksize);
-TRACE;
                bytes_remaining = bytes_remaining - blocksize;
-TRACE;
        }
 
-TRACE;
        /* Don't close it ... cache it! */
        /* fclose(tmp); */
-TRACE;
        IMAP->cached_body = tmp;
        IMAP->cached_bodymsgnum = msgnum;
        strcpy(IMAP->cached_bodypart, section);
-TRACE;
 
        if (msg != NULL) {
-TRACE;
                CtdlFreeMessage(msg);
        }
 
        /* Mark this message as "seen" *unless* this is a "peek" operation */
-TRACE;
        if (is_peek == 0) {
                CtdlSetSeen(msgnum, 1, ctdlsetseen_seen);
        }
-TRACE;
 }
 
 /*
index e8e51eb935e8ace1ce68590a8707425f63259758..697a67fbb78dccf4d2f198309e919d1b21ae4a16 100644 (file)
@@ -1102,12 +1102,10 @@ int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
                return(om_no_such_msg);
        }
        
-       TRACE;
        retcode = CtdlOutputPreLoadedMsg(
                        TheMessage, msg_num, mode,
                        headers_only, do_proto, crlf);
 
-       TRACE;
        CtdlFreeMessage(TheMessage);
 
        return(retcode);
@@ -1151,11 +1149,9 @@ int CtdlOutputPreLoadedMsg(
                msg_num,
                mode, headers_only, do_proto, crlf);
 
-       TRACE;
        snprintf(mid, sizeof mid, "%ld", msg_num);
        nl = (crlf ? "\r\n" : "\n");
 
-       TRACE;
        if (!is_valid_message(TheMessage)) {
                lprintf(CTDL_ERR,
                        "ERROR: invalid preloaded message for output\n");
@@ -1163,7 +1159,6 @@ int CtdlOutputPreLoadedMsg(
        }
 
        /* Are we downloading a MIME component? */
-       TRACE;
        if (mode == MT_DOWNLOAD) {
                if (TheMessage->cm_format_type != FMT_RFC822) {
                        if (do_proto)
@@ -1189,10 +1184,8 @@ int CtdlOutputPreLoadedMsg(
                                        desired_section);
                        }
                }
-               TRACE;
                return((CC->download_fp != NULL) ? om_ok : om_mime_error);
        }
-       TRACE;
 
        /* now for the user-mode message reading loops */
        if (do_proto) cprintf("%d Message %ld:\n", LISTING_FOLLOWS, msg_num);
@@ -1215,7 +1208,6 @@ int CtdlOutputPreLoadedMsg(
 
        /* begin header processing loop for Citadel message format */
 
-       TRACE;
        if ((mode == MT_CITADEL) || (mode == MT_MIME)) {
 
                strcpy(display_name, "<unknown>");
@@ -1279,20 +1271,16 @@ int CtdlOutputPreLoadedMsg(
        }
 
        /* begin header processing loop for RFC822 transfer format */
-       TRACE;
 
        strcpy(suser, "");
        strcpy(luser, "");
        strcpy(fuser, "");
        strcpy(snode, NODENAME);
        strcpy(lnode, HUMANNODE);
-       TRACE;
        if (mode == MT_RFC822) {
                for (i = 0; i < 256; ++i) {
-       TRACE;
                        if (TheMessage->cm_fields[i]) {
                                mptr = TheMessage->cm_fields[i];
-       TRACE;
 
                                if (i == 'A') {
                                        safestrncpy(luser, mptr, sizeof luser);
@@ -1323,23 +1311,19 @@ int CtdlOutputPreLoadedMsg(
                        }
                }
                if (subject_found == 0) {
-       TRACE;
                        cprintf("Subject: (no subject)%s", nl);
                }
        }
-       TRACE;
 
        for (i=0; i<strlen(suser); ++i) {
                suser[i] = tolower(suser[i]);
                if (!isalnum(suser[i])) suser[i]='_';
        }
-       TRACE;
 
        if (mode == MT_RFC822) {
                if (!strcasecmp(snode, NODENAME)) {
                        safestrncpy(snode, FQDN, sizeof snode);
                }
-       TRACE;
 
                /* Construct a fun message id */
                cprintf("Message-ID: <%s", mid);
@@ -1347,7 +1331,6 @@ int CtdlOutputPreLoadedMsg(
                        cprintf("@%s", snode);
                }
                cprintf(">%s", nl);
-       TRACE;
 
                if (!is_room_aide() && (TheMessage->cm_anon_type == MES_ANONONLY)) {
                        cprintf("From: x@x.org (----)%s", nl);
@@ -1363,7 +1346,6 @@ int CtdlOutputPreLoadedMsg(
                }
 
                cprintf("Organization: %s%s", lnode, nl);
-       TRACE;
 
                /* Blank line signifying RFC822 end-of-headers */
                if (TheMessage->cm_format_type != FMT_RFC822) {
@@ -1373,7 +1355,6 @@ int CtdlOutputPreLoadedMsg(
 
        /* end header processing loop ... at this point, we're in the text */
 START_TEXT:
-       TRACE;
        if (headers_only == HEADERS_FAST) goto DONE;
        mptr = TheMessage->cm_fields['M'];
 
@@ -1440,13 +1421,11 @@ START_TEXT:
        if ( (mode == MT_CITADEL) || (mode == MT_MIME) ) {
                if (do_proto) cprintf("text\n");
        }
-       TRACE;
 
        /* If the format type on disk is 1 (fixed-format), then we want
         * everything to be output completely literally ... regardless of
         * what message transfer format is in use.
         */
-       TRACE;
        if (TheMessage->cm_format_type == FMT_FIXED) {
                if (mode == MT_MIME) {
                        cprintf("Content-type: text/plain\n\n");
@@ -1474,7 +1453,6 @@ START_TEXT:
         * for new paragraphs is correct and the client will reformat the
         * message to the reader's screen width.
         */
-       TRACE;
        if (TheMessage->cm_format_type == FMT_CITADEL) {
                if (mode == MT_MIME) {
                        cprintf("Content-type: text/x-citadel-variformat\n\n");
@@ -1487,7 +1465,6 @@ START_TEXT:
         * this message is format 1 (fixed format), so the callback function
         * we use will display those parts as-is.
         */
-       TRACE;
        if (TheMessage->cm_format_type == FMT_RFC822) {
                CtdlAllocUserData(SYM_MA_INFO, sizeof(struct ma_info));
                memset(ma, 0, sizeof(struct ma_info));
@@ -1509,7 +1486,6 @@ START_TEXT:
 
 DONE:  /* now we're done */
        if (do_proto) cprintf("000\n");
-       TRACE;
        return(om_ok);
 }
 
index f63727b95bdb737352dfe8db98e79d9480faa017..1dd9080c3be4d761b6ea43b8d7de7b6915ee79f3 100644 (file)
@@ -567,15 +567,10 @@ STARTOVER:
                                 * reply's copy will have the same address, but an updated
                                 * status.)
                                 */
-                               TRACE;
                                icalcomponent_remove_property(event, e_attendee);
-                               TRACE;
                                icalproperty_free(e_attendee);
-                               TRACE;
                                icalcomponent_remove_property(reply, r_attendee);
-                               TRACE;
                                icalcomponent_add_property(event, r_attendee);
-                               TRACE;
 
                                /* Since we diddled both sets of attendees, we have to start
                                 * the iteration over again.  This will not create an infinite
index 9b64504ac70dd58acbf32d490534967cacee9403..f32bc78d6af71b83db81215e3f2598f93878c3eb 100644 (file)
@@ -91,14 +91,18 @@ char *working_ignetcfg = NULL;
  */
 void load_working_ignetcfg(void) {
        char *cfg;
+       char *oldcfg;
 
        cfg = CtdlGetSysConfig(IGNETCFG);
        if (cfg == NULL) {
                cfg = strdup("");
        }
 
-       working_ignetcfg = realloc(working_ignetcfg, strlen(cfg) + 1 );
-       strcpy(working_ignetcfg, cfg);
+       oldcfg = working_ignetcfg;
+       working_ignetcfg = cfg;
+       if (oldcfg != NULL) {
+               free(oldcfg);
+       }
 }
 
 
index 7ebfa7dd10fd4b49d04558d50938e3c965d68602..03c3e1251b2dde0f65af3645a62b374c927aea29 100644 (file)
@@ -1527,11 +1527,11 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                        "attempted|%ld\n"
                        "retry|%ld\n",
                        SPOOLMIME, instr, (long)time(NULL), (long)retry );
-               free(instr);
                CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM);
                CtdlFreeMessage(msg);
        }
 
+       free(instr);
 }
 
 
index 5fd05f55b11aca982601033aa6edc0edbe877e90..a208e6531899c1978b75d969f15e165fed911da4 100644 (file)
@@ -117,7 +117,7 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) {
        if (syslog_facility >= 0) {
                if (loglevel <= verbosity) {
                        /* Hackery -IO */
-                       if (CC && CC->cs_pid) {
+                       if (CC->cs_pid != 0) {
                                memmove(&buf[6], buf, sizeof(buf) - 6);
                                snprintf(buf, 6, "[%3d]", CC->cs_pid);
                                buf[5] = ' ';
@@ -134,22 +134,7 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) {
                /* Promote to time_t; types differ on some OSes (like darwin) */
                unixtime = tv.tv_sec;
                localtime_r(&unixtime, &tim);
-               /*
-                * Log provides millisecond accuracy.  If you need
-                * microsecond accuracy and your OS supports it, change
-                * %03ld to %06ld and remove " / 1000" after tv.tv_usec.
-                */
-               if (CC && CC->cs_pid) {
-#if 0
-                       /* Millisecond display */
-                       fprintf(stderr,
-                               "%04d/%02d/%02d %2d:%02d:%02d.%03ld [%3d] %s",
-                               tim.tm_year + 1900, tim.tm_mon + 1,
-                               tim.tm_mday, tim.tm_hour, tim.tm_min,
-                               tim.tm_sec, (long)tv.tv_usec / 1000,
-                               CC->cs_pid, buf);
-#endif
-                       /* Microsecond display */
+               if (CC->cs_pid != 0) {
                        fprintf(stderr,
                                "%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] %s",
                                tim.tm_year + 1900, tim.tm_mon + 1,
@@ -157,15 +142,6 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) {
                                tim.tm_sec, (long)tv.tv_usec,
                                CC->cs_pid, buf);
                } else {
-#if 0
-                       /* Millisecond display */
-                       fprintf(stderr,
-                               "%04d/%02d/%02d %2d:%02d:%02d.%03ld %s",
-                               tim.tm_year + 1900, tim.tm_mon + 1,
-                               tim.tm_mday, tim.tm_hour, tim.tm_min,
-                               tim.tm_sec, (long)tv.tv_usec / 1000, buf);
-#endif
-                       /* Microsecond display */
                        fprintf(stderr,
                                "%04d/%02d/%02d %2d:%02d:%02d.%06ld %s",
                                tim.tm_year + 1900, tim.tm_mon + 1,
index 0f59b34a10075e26b9c51ad3b3025a95cd78f64d..07a9649b489f674b06ab36fdc5ebf59fa7fc1810 100644 (file)
@@ -615,3 +615,12 @@ char *bmstrstr(char *text, char *pattern,
        }
        return (NULL);
 }
+
+
+/*
+ * In our world, we want strcpy() to be able to work with overlapping strings.
+ */
+char *strcpy(char *dest, const char *src) {
+       memmove(dest, src, (strlen(src) + 1) );
+       return(dest);
+}