Fix memory leak for termlist of type xtargets
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 28 Mar 2011 12:34:36 +0000 (14:34 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 28 Mar 2011 12:34:36 +0000 (14:34 +0200)
The setting_xml is now a regular string allocated on the
NMEM handle that is passed to hitsbytarget anyway.

src/http_command.c
src/session.c
src/session.h

index b3e4dc7..8c21c8c 100644 (file)
@@ -721,11 +721,10 @@ static void cmd_bytarget(struct http_channel *c)
         if (settings && *settings == '1')
         {
             wrbuf_puts(c->wrbuf, "<settings>\n");
         if (settings && *settings == '1')
         {
             wrbuf_puts(c->wrbuf, "<settings>\n");
-            wrbuf_puts(c->wrbuf, wrbuf_cstr(ht[i].settings_xml));
+            wrbuf_puts(c->wrbuf, ht[i].settings_xml);
             wrbuf_puts(c->wrbuf, "</settings>\n");
         }
         wrbuf_puts(c->wrbuf, "</target>");
             wrbuf_puts(c->wrbuf, "</settings>\n");
         }
         wrbuf_puts(c->wrbuf, "</target>");
-        wrbuf_destroy(ht[i].settings_xml);
     }
 
     wrbuf_puts(c->wrbuf, "</bytarget>");
     }
 
     wrbuf_puts(c->wrbuf, "</bytarget>");
index c0006a5..7b6e78a 100644 (file)
@@ -839,7 +839,8 @@ struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem)
         res[*count].state = client_get_state_str(cl);
         res[*count].connected  = client_get_connection(cl) ? 1 : 0;
         session_settings_dump(se, client_get_database(cl), w);
         res[*count].state = client_get_state_str(cl);
         res[*count].connected  = client_get_connection(cl) ? 1 : 0;
         session_settings_dump(se, client_get_database(cl), w);
-        res[*count].settings_xml = w;
+        res[*count].settings_xml = nmem_strdup(nmem, wrbuf_cstr(w));
+        wrbuf_destroy(w);
         (*count)++;
     }
     session_leave(se);
         (*count)++;
     }
     session_leave(se);
index 6f43d69..fdecbc4 100644 (file)
@@ -143,7 +143,7 @@ struct hitsbytarget {
     int records;
     const char *state;
     int connected;
     int records;
     const char *state;
     int connected;
-    WRBUF settings_xml;
+    char *settings_xml;
 };
 
 struct hitsbytarget *hitsbytarget(struct session *s, int *count, NMEM nmem);
 };
 
 struct hitsbytarget *hitsbytarget(struct session *s, int *count, NMEM nmem);