From e1f514ef2c6b47fffe0e9cab146be8817ba46a57 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Sun, 25 Feb 2018 19:24:58 +0100 Subject: [PATCH] lib: iostream-pump: Add iostream_pump_destroy(). This functions always stops the pump and dereferences the streams before dereferencing the pump itself. --- src/lib/iostream-pump.c | 20 +++++++++++++++++++- src/lib/iostream-pump.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) 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, -- 2.47.3