From: Art Cancro Date: Wed, 8 Feb 2006 21:53:29 +0000 (+0000) Subject: Fixed a couple of memory leaks detected by Valgrind. X-Git-Tag: v7.86~4221 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=713b381386d4f0068aa0cd1255101b959cae339f Fixed a couple of memory leaks detected by Valgrind. --- diff --git a/webcit/context_loop.c b/webcit/context_loop.c index 467b559f8..f430099c9 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -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); diff --git a/webcit/cookie_conversion.c b/webcit/cookie_conversion.c index 7504b981c..24e29ce74 100644 --- a/webcit/cookie_conversion.c +++ b/webcit/cookie_conversion.c @@ -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; } /** diff --git a/webcit/gettext.c b/webcit/gettext.c index 453633cd1..70af1ef5a 100644 --- a/webcit/gettext.c +++ b/webcit/gettext.c @@ -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. */ diff --git a/webcit/html2html.c b/webcit/html2html.c index 05bc77a93..b1eb4b0bb 100644 --- a/webcit/html2html.c +++ b/webcit/html2html.c @@ -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(""); wprintf(_("realloc() error! couldn't get %d bytes: %s"), buffer_length + 1, strerror(errno)); wprintf("

\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"); diff --git a/webcit/messages.c b/webcit/messages.c index edbc64ba0..724dab8c5 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -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; diff --git a/webcit/roomops.c b/webcit/roomops.c index 382339e43..8fe2b8277 100644 --- a/webcit/roomops.c +++ b/webcit/roomops.c @@ -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]; diff --git a/webcit/tools.c b/webcit/tools.c index 809afee94..df27503ff 100644 --- a/webcit/tools.c +++ b/webcit/tools.c @@ -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) diff --git a/webcit/webcit.h b/webcit/webcit.h index eababbed8..0bc43474b 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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);