eventscript: fix cleanup path when setting up script list
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 18 Dec 2009 01:24:24 +0000 (11:54 +1030)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 18 Dec 2009 01:31:34 +0000 (12:31 +1100)
We shouldn't set ctdb->current_monitor until we set destructor: that's
what cleans it up.

Also, free state->scripts on no-scripts exit path: it's not a child of
state because we need it in the destructor.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
server/eventscript.c

index 803ac1daa004e14f5b23ffc578ee3eaaca5ffd70..b0224074dff4ced96923a87362beb7f1325c61f1 100644 (file)
@@ -638,10 +638,6 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
                ctdb->current_monitor = NULL;
        }
 
-       if (!from_user && (call == CTDB_EVENT_MONITOR || call == CTDB_EVENT_STATUS)) {
-               ctdb->current_monitor = state;
-       }
-
        DEBUG(DEBUG_INFO,(__location__ " Starting eventscript %s %s\n",
                          ctdb_eventscript_call_names[state->call],
                          state->options));
@@ -657,6 +653,7 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
        /* Nothing to do? */
        if (state->scripts->num_scripts == 0) {
                ctdb->event_script_timeouts = 0;
+               talloc_free(state->scripts);
                talloc_free(state);
                return 0;
        }
@@ -668,6 +665,10 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
                return -1;
        }
 
+       if (!from_user && (call == CTDB_EVENT_MONITOR || call == CTDB_EVENT_STATUS)) {
+               ctdb->current_monitor = state;
+       }
+
        talloc_set_destructor(state, event_script_destructor);
        if (!timeval_is_zero(&state->timeout)) {
                event_add_timed(ctdb->ev, state, timeval_current_ofs(state->timeout.tv_sec, state->timeout.tv_usec), ctdb_event_script_timeout, state);