]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
DB output: fix crash in SIGHUP handling
authorEric Leblond <eric@inl.fr>
Sun, 19 Sep 2010 17:55:41 +0000 (19:55 +0200)
committerEric Leblond <eric@inl.fr>
Tue, 21 Sep 2010 23:36:42 +0000 (01:36 +0200)
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

index 184ad86f90726eeeb23fd3c9dbfda890fe37a31c..8d812c71d3a9443432f45bb1ba59aa7944a5bf36 100644 (file)
--- 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: