]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: iostream-pump: Add iostream_pump_destroy().
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 25 Feb 2018 18:24:58 +0000 (19:24 +0100)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Sun, 18 Mar 2018 10:53:18 +0000 (12:53 +0200)
This functions always stops the pump and dereferences the streams before
dereferencing the pump itself.

src/lib/iostream-pump.c
src/lib/iostream-pump.h

index 29129af469e74a735875e3e9fc60c4afeb1d6542..85fe8eb405449ac02f9deb935d8e6f27d652ef59 100644 (file)
@@ -191,11 +191,29 @@ void iostream_pump_unref(struct iostream_pump **_pump)
        i_free(pump);
 }
 
+void iostream_pump_destroy(struct iostream_pump **_pump)
+{
+       i_assert(_pump != NULL);
+       struct iostream_pump *pump = *_pump;
+
+       if (pump == NULL)
+               return;
+
+       *_pump = NULL;
+
+       iostream_pump_stop(pump);
+       o_stream_unref(&pump->output);
+       i_stream_unref(&pump->input);
+
+       iostream_pump_unref(&pump);
+}
+
 void iostream_pump_stop(struct iostream_pump *pump)
 {
        i_assert(pump != NULL);
 
-       o_stream_unset_flush_callback(pump->output);
+       if (pump->output != NULL)
+               o_stream_unset_flush_callback(pump->output);
 
        io_remove(&pump->io);
 }
index e0fd0eb53c4acf88ace6e5246e2e6e7432462de2..44dc8428d36f6ed65104eb3eb06222dd31aac518 100644 (file)
@@ -44,6 +44,7 @@ void iostream_pump_stop(struct iostream_pump *pump);
 
 void iostream_pump_ref(struct iostream_pump *pump);
 void iostream_pump_unref(struct iostream_pump **_pump);
+void iostream_pump_destroy(struct iostream_pump **_pump);
 
 void iostream_pump_set_completion_callback(struct iostream_pump *pump,
                                           iostream_pump_callback_t *callback,