From f1262b46f67e6a99d12052da93e8157e0935783c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 23 Dec 2020 15:28:32 +0000 Subject: [Minor] Fix lifetime This is a reason why I hate C --- src/libserver/http/http_router.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libserver/http/http_router.c b/src/libserver/http/http_router.c index 9f36118b2..a5b960e72 100644 --- a/src/libserver/http/http_router.c +++ b/src/libserver/http/http_router.c @@ -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; } -- cgit v1.2.3