]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix lifetime
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 23 Dec 2020 15:28:32 +0000 (15:28 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 23 Dec 2020 15:28:32 +0000 (15:28 +0000)
This is a reason why I hate C

src/libserver/http/http_router.c

index 9f36118b27f9c6d4844ecbb8b2c395b8f0ce73e4..a5b960e723f9bf0305752bb05ef5170eff36b4c2 100644 (file)
@@ -254,6 +254,7 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
        guint i;
        rspamd_regexp_t *re;
        struct rspamd_http_connection_router *router;
+       gchar *pathbuf = NULL;
 
        G_STATIC_ASSERT (sizeof (rspamd_http_router_handler_t) ==
                                         sizeof (gpointer));
@@ -286,7 +287,6 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
 
                /* Search for path */
                if (msg->url != NULL && msg->url->len != 0) {
-                       gchar *pathbuf = NULL;
 
                        http_parser_parse_url (msg->url->str, msg->url->len, TRUE, &u);
 
@@ -312,10 +312,6 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
                        found = g_hash_table_lookup (entry->rt->paths, &lookup);
                        memcpy (&handler, &found, sizeof (found));
                        msg_debug ("requested known path: %T", &lookup);
-
-                       if (pathbuf) {
-                               g_free (pathbuf);
-                       }
                }
                else {
                        err = g_error_new (HTTP_ERROR, 404,
@@ -340,6 +336,10 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
                }
 
                if (handler != NULL) {
+                       if (pathbuf) {
+                               g_free (pathbuf);
+                       }
+
                        return handler (entry, msg);
                }
                else {
@@ -351,6 +351,10 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
                                        found = rspamd_regexp_get_ud (re);
                                        memcpy (&handler, &found, sizeof (found));
 
+                                       if (pathbuf) {
+                                               g_free (pathbuf);
+                                       }
+
                                        return handler (entry, msg);
                                }
                        }
@@ -372,6 +376,10 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
                }
        }
 
+       if (pathbuf) {
+               g_free (pathbuf);
+       }
+
        return 0;
 }