From 06f6b280486aa32404b3c2a13e7954b3217708b7 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sat, 17 Oct 2015 18:01:58 +0300 Subject: [PATCH] Fix to MXS-412: https://mariadb.atlassian.net/browse/MXS-412 service->user is now set to NULL after the users are freed. --- server/core/service.c | 9 ++++++--- server/modules/routing/debugcmd.c | 24 +++++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/server/core/service.c b/server/core/service.c index 0515c5218..b209c99d4 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -258,8 +258,8 @@ GWPROTOCOL *funcs; } if (loaded == -1) { - hashtable_free(service->users->data); - free(service->users); + users_free(service->users); + service->users = NULL; dcb_close(port->listener); port->listener = NULL; goto retblock; @@ -346,6 +346,7 @@ GWPROTOCOL *funcs; == NULL) { users_free(service->users); + service->users = NULL; dcb_close(port->listener); port->listener = NULL; LOGIF(LE, (skygw_log_write_flush( @@ -380,7 +381,8 @@ GWPROTOCOL *funcs; service->name))); users_free(service->users); - dcb_close(port->listener); + service->users = NULL; + dcb_close(port->listener); port->listener = NULL; goto retblock; } @@ -394,6 +396,7 @@ GWPROTOCOL *funcs; port->protocol, service->name))); users_free(service->users); + service->users = NULL; dcb_close(port->listener); port->listener = NULL; } diff --git a/server/modules/routing/debugcmd.c b/server/modules/routing/debugcmd.c index b88a67a19..bd15b54ec 100644 --- a/server/modules/routing/debugcmd.c +++ b/server/modules/routing/debugcmd.c @@ -678,13 +678,14 @@ static struct { * Convert a string argument to a numeric, observing prefixes * for number bases, e.g. 0x for hex, 0 for octal * + * @param dcb The client DCB * @param mode The CLI mode * @param arg The string representation of the argument * @param arg_type The target type for the argument * @return The argument as a long integer */ static unsigned long -convert_arg(int mode, char *arg, int arg_type) +convert_arg(DCB* dcb, int mode, char *arg, int arg_type) { unsigned long rval; SERVICE *service; @@ -710,9 +711,18 @@ SERVICE *service; { service = service_find(arg); if (service) + { + if(service->users == NULL) + { + dcb_printf(dcb, "The dbusers for service %s are not loaded. " + "Reload the dbusers and try again.\n", service->name); + } return (unsigned long)(service->users); + } else + { return 0; + } } return rval; case ARG_TYPE_DCB: @@ -927,7 +937,7 @@ int nskip = 0; cmds[i].options[j].fn(dcb); break; case 1: - arg1 = convert_arg(cli->mode, args[2],cmds[i].options[j].arg_types[0]); + arg1 = convert_arg(dcb, cli->mode, args[2],cmds[i].options[j].arg_types[0]); if (arg1) cmds[i].options[j].fn(dcb, arg1); @@ -936,8 +946,8 @@ int nskip = 0; args[2]); break; case 2: - arg1 = convert_arg(cli->mode, args[2],cmds[i].options[j].arg_types[0]); - arg2 = convert_arg(cli->mode, args[3],cmds[i].options[j].arg_types[1]); + arg1 = convert_arg(dcb, cli->mode, args[2],cmds[i].options[j].arg_types[0]); + arg2 = convert_arg(dcb, cli->mode, args[3],cmds[i].options[j].arg_types[1]); if (arg1 && arg2) cmds[i].options[j].fn(dcb, arg1, arg2); else if (arg1 == 0) @@ -948,9 +958,9 @@ int nskip = 0; args[3]); break; case 3: - arg1 = convert_arg(cli->mode, args[2],cmds[i].options[j].arg_types[0]); - arg2 = convert_arg(cli->mode, args[3],cmds[i].options[j].arg_types[1]); - arg3 = convert_arg(cli->mode, args[4],cmds[i].options[j].arg_types[2]); + arg1 = convert_arg(dcb, cli->mode, args[2],cmds[i].options[j].arg_types[0]); + arg2 = convert_arg(dcb, cli->mode, args[3],cmds[i].options[j].arg_types[1]); + arg3 = convert_arg(dcb, cli->mode, args[4],cmds[i].options[j].arg_types[2]); if (arg1 && arg2 && arg3) cmds[i].options[j].fn(dcb, arg1, arg2, arg3); else if (arg1 == 0)