From: Stephan Bosch Date: Sun, 25 Feb 2018 18:24:58 +0000 (+0100) Subject: lib: iostream-pump: Add iostream_pump_destroy(). X-Git-Tag: 2.3.9~2113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1f514ef2c6b47fffe0e9cab146be8817ba46a57;p=thirdparty%2Fdovecot%2Fcore.git lib: iostream-pump: Add iostream_pump_destroy(). This functions always stops the pump and dereferences the streams before dereferencing the pump itself. --- diff --git a/src/lib/iostream-pump.c b/src/lib/iostream-pump.c index 29129af469..85fe8eb405 100644 --- a/src/lib/iostream-pump.c +++ b/src/lib/iostream-pump.c @@ -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); } diff --git a/src/lib/iostream-pump.h b/src/lib/iostream-pump.h index e0fd0eb53c..44dc8428d3 100644 --- a/src/lib/iostream-pump.h +++ b/src/lib/iostream-pump.h @@ -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,