From 58e654e1deda9d230dfb1d64bec773233a19ef84 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sun, 19 Sep 2010 19:55:41 +0200 Subject: DB output: fix crash in SIGHUP handling This patch fixes the handling of SIGHUP when a SQL plugin is used. A freed structure was previoulsy used to build the request and this was leading to a crash. --- util/db.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/util/db.c b/util/db.c index 184ad86..8d812c7 100644 --- a/util/db.c +++ b/util/db.c @@ -190,18 +190,12 @@ int ulogd_db_start(struct ulogd_pluginstance *upi) return ret; } -int ulogd_db_stop(struct ulogd_pluginstance *upi) +static int ulogd_db_instance_stop(struct ulogd_pluginstance *upi) { struct db_instance *di = (struct db_instance *) upi->private; ulogd_log(ULOGD_NOTICE, "stopping\n"); di->driver->close_db(upi); - /* try to free our dynamically allocated input key array */ - if (upi->input.keys) { - free(upi->input.keys); - upi->input.keys = NULL; - } - /* try to free the buffer for insert statement */ if (di->stmt) { free(di->stmt); @@ -211,6 +205,19 @@ int ulogd_db_stop(struct ulogd_pluginstance *upi) return 0; } +int ulogd_db_stop(struct ulogd_pluginstance *upi) +{ + ulogd_db_instance_stop(upi); + + /* try to free our dynamically allocated input key array */ + if (upi->input.keys) { + free(upi->input.keys); + upi->input.keys = NULL; + } + + return 0; +} + static int _init_reconnect(struct ulogd_pluginstance *upi) { @@ -356,7 +363,7 @@ void ulogd_db_signal(struct ulogd_pluginstance *upi, int signal) switch (signal) { case SIGHUP: /* reopen database connection */ - ulogd_db_stop(upi); + ulogd_db_instance_stop(upi); ulogd_db_start(upi); break; default: -- cgit v1.2.3