Fixes for close and cleanup of sessions, dcb, router sessions etc.
Fix memory leak in config Fix for debug command execution without second argument
This commit is contained in:
@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
|
|
||||||
static int process_config_context(CONFIG_CONTEXT *);
|
static int process_config_context(CONFIG_CONTEXT *);
|
||||||
|
static void free_config_context(CONFIG_CONTEXT *);
|
||||||
static char *config_get_value(CONFIG_PARAMETER *, const char *);
|
static char *config_get_value(CONFIG_PARAMETER *, const char *);
|
||||||
|
|
||||||
|
|
||||||
@ -91,6 +92,7 @@ int
|
|||||||
load_config(char *file)
|
load_config(char *file)
|
||||||
{
|
{
|
||||||
CONFIG_CONTEXT config;
|
CONFIG_CONTEXT config;
|
||||||
|
int rval;
|
||||||
|
|
||||||
config.object = "";
|
config.object = "";
|
||||||
config.next = NULL;
|
config.next = NULL;
|
||||||
@ -98,7 +100,10 @@ CONFIG_CONTEXT config;
|
|||||||
if (ini_parse(file, handler, &config) < 0)
|
if (ini_parse(file, handler, &config) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return process_config_context(config.next);
|
rval = process_config_context(config.next);
|
||||||
|
free_config_context(config.next);
|
||||||
|
|
||||||
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -217,3 +222,32 @@ config_get_value(CONFIG_PARAMETER *params, const char *name)
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free a config tree
|
||||||
|
*
|
||||||
|
* @param context The configuration data
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
free_config_context(CONFIG_CONTEXT *context)
|
||||||
|
{
|
||||||
|
CONFIG_CONTEXT *obj;
|
||||||
|
CONFIG_PARAMETER *p1, *p2;
|
||||||
|
|
||||||
|
while (context)
|
||||||
|
{
|
||||||
|
free(context->object);
|
||||||
|
p1 = context->parameters;
|
||||||
|
while (p1)
|
||||||
|
{
|
||||||
|
free(p1->name);
|
||||||
|
free(p1->value);
|
||||||
|
p2 = p1->next;
|
||||||
|
free(p1);
|
||||||
|
p1 = p2;
|
||||||
|
}
|
||||||
|
obj = context->next;
|
||||||
|
free(context);
|
||||||
|
context = obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
26
core/dcb.c
26
core/dcb.c
@ -43,6 +43,7 @@
|
|||||||
#include <session.h>
|
#include <session.h>
|
||||||
#include <service.h>
|
#include <service.h>
|
||||||
#include <modules.h>
|
#include <modules.h>
|
||||||
|
#include <router.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <gw.h>
|
#include <gw.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
@ -79,6 +80,8 @@ DCB *rval;
|
|||||||
rval->remote = NULL;
|
rval->remote = NULL;
|
||||||
rval->state = DCB_STATE_ALLOC;
|
rval->state = DCB_STATE_ALLOC;
|
||||||
rval->next = NULL;
|
rval->next = NULL;
|
||||||
|
rval->data = NULL;
|
||||||
|
rval->protocol = NULL;
|
||||||
memset(&rval->stats, 0, sizeof(DCBSTATS)); // Zero the statistics
|
memset(&rval->stats, 0, sizeof(DCBSTATS)); // Zero the statistics
|
||||||
|
|
||||||
spinlock_acquire(dcbspin);
|
spinlock_acquire(dcbspin);
|
||||||
@ -119,6 +122,10 @@ dcb_free(DCB *dcb)
|
|||||||
}
|
}
|
||||||
spinlock_release(dcbspin);
|
spinlock_release(dcbspin);
|
||||||
|
|
||||||
|
if (dcb->protocol)
|
||||||
|
free(dcb->protocol);
|
||||||
|
if (dcb->data)
|
||||||
|
free(dcb->data);
|
||||||
if (dcb->remote)
|
if (dcb->remote)
|
||||||
free(dcb->remote);
|
free(dcb->remote);
|
||||||
free(dcb);
|
free(dcb);
|
||||||
@ -352,8 +359,27 @@ int saved_errno = 0;
|
|||||||
void
|
void
|
||||||
dcb_close(DCB *dcb)
|
dcb_close(DCB *dcb)
|
||||||
{
|
{
|
||||||
|
poll_remove_dcb(dcb);
|
||||||
close(dcb->fd);
|
close(dcb->fd);
|
||||||
dcb->state = DCB_STATE_DISCONNECTED;
|
dcb->state = DCB_STATE_DISCONNECTED;
|
||||||
|
|
||||||
|
if (dcb_isclient(dcb))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If the DCB we are closing is a client side DCB then shutdown the
|
||||||
|
* router session. This will close any backend connections.
|
||||||
|
*/
|
||||||
|
SERVICE *service = dcb->session->service;
|
||||||
|
|
||||||
|
if (service && service->router)
|
||||||
|
{
|
||||||
|
service->router->closeSession(service->router_instance,
|
||||||
|
dcb->session->router_session);
|
||||||
|
}
|
||||||
|
|
||||||
|
session_free(dcb->session);
|
||||||
|
}
|
||||||
|
dcb_free(dcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,7 +234,7 @@ dcb.o: dcb.c /usr/include/stdio.h /usr/include/features.h \
|
|||||||
/usr/include/sched.h /usr/include/bits/sched.h \
|
/usr/include/sched.h /usr/include/bits/sched.h \
|
||||||
/usr/include/bits/setjmp.h ../include/buffer.h ../include/server.h \
|
/usr/include/bits/setjmp.h ../include/buffer.h ../include/server.h \
|
||||||
../include/session.h ../include/service.h ../include/modules.h \
|
../include/session.h ../include/service.h ../include/modules.h \
|
||||||
/usr/include/errno.h /usr/include/bits/errno.h \
|
../include/router.h /usr/include/errno.h /usr/include/bits/errno.h \
|
||||||
/usr/include/linux/errno.h /usr/include/asm/errno.h \
|
/usr/include/linux/errno.h /usr/include/asm/errno.h \
|
||||||
/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \
|
/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \
|
||||||
../include/gw.h /usr/include/ctype.h /usr/include/netdb.h \
|
../include/gw.h /usr/include/ctype.h /usr/include/netdb.h \
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
#include <thread.h>
|
#include <thread.h>
|
||||||
|
|
||||||
typedef struct spinlock {
|
typedef struct spinlock {
|
||||||
volatile int lock;
|
int lock;
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
int spins;
|
int spins;
|
||||||
int acquired;
|
int acquired;
|
||||||
|
@ -783,13 +783,9 @@ int gw_read_client_event(DCB* dcb) {
|
|||||||
// dcb still to be freed
|
// dcb still to be freed
|
||||||
|
|
||||||
// this will propagate COM_QUIT to backends
|
// this will propagate COM_QUIT to backends
|
||||||
//router->routeQuery(router_instance, rsession, queue);
|
router->routeQuery(router_instance, rsession, queue);
|
||||||
// close client
|
// close client
|
||||||
//(dcb->func).close(dcb);
|
(dcb->func).close(dcb);
|
||||||
// remove dcb
|
|
||||||
//poll_remove_dcb(dcb);
|
|
||||||
// close the session
|
|
||||||
//router->closeSession(router_instance, rsession);
|
|
||||||
// call errors, it will be removed after tests
|
// call errors, it will be removed after tests
|
||||||
//(dcb->func).error(dcb);
|
//(dcb->func).error(dcb);
|
||||||
|
|
||||||
|
@ -170,10 +170,6 @@ closeSession(ROUTER *instance, void *router_session)
|
|||||||
CLI_INSTANCE *inst = (CLI_INSTANCE *)instance;
|
CLI_INSTANCE *inst = (CLI_INSTANCE *)instance;
|
||||||
CLI_SESSION *session = (CLI_SESSION *)router_session;
|
CLI_SESSION *session = (CLI_SESSION *)router_session;
|
||||||
|
|
||||||
/*
|
|
||||||
* Close the connection to the backend
|
|
||||||
*/
|
|
||||||
session->session->client->func.close(session->session->client);
|
|
||||||
|
|
||||||
spinlock_acquire(&inst->lock);
|
spinlock_acquire(&inst->lock);
|
||||||
if (inst->sessions == session)
|
if (inst->sessions == session)
|
||||||
|
@ -180,7 +180,7 @@ char *saveptr, *delim = " \t\r\n";
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else if (argc >= 0)
|
||||||
{
|
{
|
||||||
for (i = 0; cmds[i].cmd; i++)
|
for (i = 0; cmds[i].cmd; i++)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user