Fixed a couple of memory leaks detected by Valgrind.
authorArt Cancro <ajc@citadel.org>
Wed, 8 Feb 2006 21:53:29 +0000 (21:53 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 8 Feb 2006 21:53:29 +0000 (21:53 +0000)
webcit/context_loop.c
webcit/cookie_conversion.c
webcit/gettext.c
webcit/html2html.c
webcit/messages.c
webcit/roomops.c
webcit/tools.c
webcit/webcit.h

index 467b559f881d4fb9a327897bf0b45df0133f298e..f430099c9a67a313cc07b28598839022ea270f3f 100644 (file)
@@ -96,6 +96,7 @@ void do_housekeeping(void)
                        free(sessions_to_kill->cache_fold);
                }
                free_attachments(sessions_to_kill);
+               free_march_list(sessions_to_kill);
                pthread_mutex_unlock(&sessions_to_kill->SessionMutex);
                sptr = sessions_to_kill->next;
                free(sessions_to_kill);
index 7504b981c0cdd2be8cc78ad7b9436afb89967c72..24e29ce740872f44a6bda5601b6ddba7862b2bf2 100644 (file)
@@ -40,22 +40,24 @@ void stuff_to_cookie(char *cookie, int session,
 }
 
 /**
- * \brief some bytefoo ????
- * \param in the string to chop
- * \param len the length of the string
- * \return the corrosponding integer value
+ * \brief      Convert unpacked hex string to an integer
+ * \param      in      Input hex string
+ * \param      len     the length of the string
+ * \return     the corrosponding integer value
  */
 int xtoi(char *in, size_t len)
 {
-    int val = 0;
-    while (isxdigit((byte) *in) && (len-- > 0)) {
-       char c = *in++;
-       val <<= 4;
-       val += isdigit((unsigned char)c)
-           ? (c - '0')
-           : (tolower((unsigned char)c) - 'a' + 10);
-    }
-    return val;
+       int val = 0;
+       char c = 0;
+       while (isxdigit((byte) *in) && (len-- > 0))
+       {
+               c = *in++;
+               val <<= 4;
+               val += isdigit((unsigned char)c)
+               ? (c - '0')
+               : (tolower((unsigned char)c) - 'a' + 10);
+       }
+       return val;
 }
 
 /**
index 453633cd1b327904e697e7d4b00edcec3ab2d33c..70af1ef5a9714c824061d1081aa39376ca875aa9 100644 (file)
@@ -60,8 +60,6 @@ void httplang_to_locale(char *LocaleString)
        int nBest;
        int nParts;
        char *search = (char *) malloc(len);
-       // locale_t my_Locale;
-       // locale_t my_Empty_Locale;
        
        memcpy(search, LocaleString, len);
        search[len] = '\0';
@@ -147,7 +145,9 @@ void httplang_to_locale(char *LocaleString)
                nBest=0;
        WC->selected_language=nBest;
        lprintf(9, "language found: %s\n", AvailLang[WC->selected_language]);
-       //      set_selected_language(selected_locale);
+       if (search != NULL) {
+               free(search);
+       }
 }
 
 /* TODO: we skip the language weightening so far. */
index 05bc77a935f1ae189f98f7a1cce0037a6755bf14..b1eb4b0bb5d8967e673cfc43c43af99b54100625 100644 (file)
@@ -103,15 +103,20 @@ void output_html(char *supplied_charset, int treat_as_wiki) {
        while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
                line_length = strlen(buf);
                buffer_length = content_length + line_length + 2;
-               msg = realloc(msg, buffer_length);
-               if (msg == NULL) {
+               ptr = realloc(msg, buffer_length);
+               if (ptr == NULL) {
                        wprintf("<b>");
                        wprintf(_("realloc() error! couldn't get %d bytes: %s"),
                                buffer_length + 1,
                                strerror(errno));
                        wprintf("</b><br /><br />\n");
+                       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+                               /** flush */
+                       }
+                       free(msg);
                        return;
                }
+               msg = ptr;
                strcpy(&msg[content_length], buf);
                content_length += line_length;
                strcpy(&msg[content_length], "\n");
index edbc64ba05064128c1be8e7854034e5953b4d448..724dab8c55b522b6ea79e2f50333e6d13b56a94e 100644 (file)
@@ -101,7 +101,6 @@ void utf8ify_rfc822_string(char *buf) {
 
                ic = ctdl_iconv_open("UTF-8", charset);
                if (ic != (iconv_t)(-1) ) {
-                       obuf = malloc(1024);
                        obuflen = 1024;
                        obuf = (char *) malloc(obuflen);
                        osav = obuf;
index 382339e43e6da6f4a31d7c3e7b94d4ef6aa318ee..8fe2b827704aecfda2c2cfc3a2f8d3cd2fe0f3da 100644 (file)
@@ -70,6 +70,25 @@ void load_floorlist(void)
 }
 
 
+/**
+ * \brief      Free a session's march list
+ *
+ * \param      wcf             Pointer to session being cleared
+ */
+void free_march_list(struct wcsession *wcf)
+{
+       struct march *mptr;
+
+       while (wcf->march == NULL) {
+               mptr = wcf->march->next;
+               free(wcf->march);
+               wcf->march = mptr;
+       }
+
+}
+
+
+
 /**
  * \brief remove a room from the march list
  */
@@ -742,7 +761,7 @@ char *pop_march(int desired_floor)
  */
 void gotonext(void)
 {
-       char buf[SIZ];
+       char buf[256];
        struct march *mptr, *mptr2;
        char next_room[128];
 
index 809afee948cd49c24c3bb09a7f483192a3fc83fb..df27503ffe072b5d916e122a1007fa84337386a2 100644 (file)
@@ -45,7 +45,7 @@ char *safestrncpy(char *dest, const char *src, size_t n)
  */
 int num_tokens(char *source, char tok)
 {
-       int a;
+       int a = 0;
        int count = 1;
 
        if (source == NULL)
index eababbed8c2eb5ca8c0466e5eb13a4828e68aa6f..0bc43474bdaa8d72565c6cb003cc8e325ff0686f 100644 (file)
@@ -612,6 +612,7 @@ int load_msg_ptrs(char *servcmd, int with_headers);
 void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen);
 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
 void free_attachments(struct wcsession *sess);
+void free_march_list(struct wcsession *wcf);
 void set_room_policy(void);
 void display_inetconf(void);
 void save_inetconf(void);