Fixed a couple of memory leaks detected by Valgrind.
[citadel.git] / webcit / html2html.c
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");