]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix multiple values headers freeing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 4 Aug 2016 15:38:52 +0000 (16:38 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 4 Aug 2016 15:38:52 +0000 (16:38 +0100)
src/libutil/http.c

index 7e5da1b12bb0f5057a243df7ce0744cada38ea68..c9410690c9d4e94a86cb9178f1e8e92a8a4c139b 100644 (file)
@@ -534,14 +534,13 @@ rspamd_http_finish_header (struct rspamd_http_connection *conn,
        HASH_FIND (hh, priv->msg->headers, priv->header->name->begin,
                        priv->header->name->len, hdr);
 
-       if (hdr) {
-               DL_APPEND (priv->msg->headers, priv->header);
-       }
-       else {
+       if (hdr == NULL) {
                HASH_ADD_KEYPTR (hh, priv->msg->headers, priv->header->name->begin,
                                priv->header->name->len, priv->header);
        }
 
+       DL_APPEND (hdr, priv->header);
+
 
        rspamd_http_check_special_header (conn, priv);
 }
@@ -549,7 +548,7 @@ rspamd_http_finish_header (struct rspamd_http_connection *conn,
 static void
 rspamd_http_init_header (struct rspamd_http_connection_private *priv)
 {
-       priv->header = g_slice_alloc (sizeof (struct rspamd_http_header));
+       priv->header = g_slice_alloc0 (sizeof (struct rspamd_http_header));
        priv->header->name = g_slice_alloc0 (sizeof (*priv->header->name));
        priv->header->value = g_slice_alloc0 (sizeof (*priv->header->value));
        priv->header->combined = rspamd_fstring_new ();
@@ -2571,15 +2570,18 @@ rspamd_http_connection_set_max_size (struct rspamd_http_connection *conn,
 void
 rspamd_http_message_free (struct rspamd_http_message *msg)
 {
-       struct rspamd_http_header *hdr, *htmp;
+       struct rspamd_http_header *hdr, *htmp, *hcur, *hcurtmp;
 
 
        HASH_ITER (hh, msg->headers, hdr, htmp) {
                HASH_DEL (msg->headers, hdr);
-               rspamd_fstring_free (hdr->combined);
-               g_slice_free1 (sizeof (*hdr->name), hdr->name);
-               g_slice_free1 (sizeof (*hdr->value), hdr->value);
-               g_slice_free1 (sizeof (struct rspamd_http_header), hdr);
+
+               DL_FOREACH_SAFE (hdr, hcur, hcurtmp) {
+                       rspamd_fstring_free (hcur->combined);
+                       g_slice_free1 (sizeof (*hcur->name), hcur->name);
+                       g_slice_free1 (sizeof (*hcur->value), hcur->value);
+                       g_slice_free1 (sizeof (struct rspamd_http_header), hcur);
+               }
        }