From 897fee715d336b15d1e781e5b877bf40555b3d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 15 Feb 2019 11:58:20 +0200 Subject: [PATCH] MXS-2302: Use const char* in hintfilter functions --- include/maxscale/hint.h | 2 +- server/core/hint.cc | 2 +- server/modules/filter/hintfilter/hintparser.cc | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/maxscale/hint.h b/include/maxscale/hint.h index 83f48d7fb..a5dd33800 100644 --- a/include/maxscale/hint.h +++ b/include/maxscale/hint.h @@ -83,7 +83,7 @@ typedef struct hint } HINT; HINT* hint_alloc(HINT_TYPE, void*, unsigned int); -HINT* hint_create_parameter(HINT*, char*, const char*); +HINT* hint_create_parameter(HINT*, const char*, const char*); HINT* hint_create_route(HINT*, HINT_TYPE, const char*); HINT* hint_splice(HINT* head, HINT* list); void hint_free(HINT*); diff --git a/server/core/hint.cc b/server/core/hint.cc index 985e3e1cd..24d87180f 100644 --- a/server/core/hint.cc +++ b/server/core/hint.cc @@ -145,7 +145,7 @@ HINT* hint_splice(HINT* head, HINT* list) * @param value The parameter value * @return The result hint list */ -HINT* hint_create_parameter(HINT* head, char* pname, const char* value) +HINT* hint_create_parameter(HINT* head, const char* pname, const char* value) { HINT* hint; diff --git a/server/modules/filter/hintfilter/hintparser.cc b/server/modules/filter/hintfilter/hintparser.cc index d95d9d3fa..d08edcd6c 100644 --- a/server/modules/filter/hintfilter/hintparser.cc +++ b/server/modules/filter/hintfilter/hintparser.cc @@ -55,8 +55,8 @@ static struct static HINT_TOKEN* hint_next_token(GWBUF** buf, char** ptr); static void hint_pop(HINT_SESSION*); -static HINT* lookup_named_hint(HINT_SESSION*, char*); -static void create_named_hint(HINT_SESSION*, char*, HINT*); +static HINT* lookup_named_hint(HINT_SESSION*, const char*); +static void create_named_hint(HINT_SESSION*, const char*, HINT*); static void hint_push(HINT_SESSION*, HINT*); static const char* token_get_keyword(HINT_TOKEN* token); static void token_free(HINT_TOKEN* token); @@ -492,7 +492,6 @@ HINT* hint_parser(HINT_SESSION* session, GWBUF* request) /* We starting an already define set of named hints */ rval = lookup_named_hint(session, hintname); hint_push(session, hint_dup(rval)); - MXS_FREE(hintname); rval = NULL; } else if (hintname == NULL && rval == NULL) @@ -529,6 +528,8 @@ HINT* hint_parser(HINT_SESSION* session, GWBUF* request) } retblock: + MXS_FREE(hintname); + if (rval == NULL) { /* No new hint parsed in this statement, apply the current @@ -705,7 +706,7 @@ static void hint_push(HINT_SESSION* session, HINT* hint) * @param name The name to lookup * @return the HINT or NULL if the name was not found. */ -static HINT* lookup_named_hint(HINT_SESSION* session, char* name) +static HINT* lookup_named_hint(HINT_SESSION* session, const char* name) { NAMEDHINTS* ptr = session->named_hints; @@ -727,7 +728,7 @@ static HINT* lookup_named_hint(HINT_SESSION* session, char* name) * @param name The name of the block to ceate * @param hint The hints themselves */ -static void create_named_hint(HINT_SESSION* session, char* name, HINT* hint) +static void create_named_hint(HINT_SESSION* session, const char* name, HINT* hint) { NAMEDHINTS* block; @@ -736,7 +737,7 @@ static void create_named_hint(HINT_SESSION* session, char* name, HINT* hint) return; } - block->name = name; + block->name = MXS_STRDUP(name); block->hints = hint_dup(hint); block->next = session->named_hints; session->named_hints = block;