From: Stephan Bosch Date: Sun, 25 Feb 2018 18:13:18 +0000 (+0100) Subject: lib: iostream-pump: Make iostream_pump_unref() implementation match other similar... X-Git-Tag: 2.3.2.rc1~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=28983eb41c81f8e63d95ae679983491b8ecfe673;p=thirdparty%2Fdovecot%2Fcore.git lib: iostream-pump: Make iostream_pump_unref() implementation match other similar code. This also means that iostream_pump_unref(NULL) is now a no-op. --- diff --git a/src/lib/iostream-pump.c b/src/lib/iostream-pump.c index 9cc5b8896c..51ad8d040a 100644 --- a/src/lib/iostream-pump.c +++ b/src/lib/iostream-pump.c @@ -159,19 +159,26 @@ void iostream_pump_ref(struct iostream_pump *pump) pump->ref++; } -void iostream_pump_unref(struct iostream_pump **pump_r) +void iostream_pump_unref(struct iostream_pump **_pump) { - i_assert(pump_r != NULL && *pump_r != NULL); - struct iostream_pump *pump = *pump_r; - *pump_r = NULL; + i_assert(_pump != NULL); + struct iostream_pump *pump = *_pump; + + if (pump == NULL) + return; i_assert(pump->ref > 0); - if (--pump->ref == 0) { - iostream_pump_stop(pump); - o_stream_unref(&pump->output); - i_stream_unref(&pump->input); - i_free(pump); - } + + *_pump = NULL; + + if (--pump->ref > 0) + return; + + iostream_pump_stop(pump); + + o_stream_unref(&pump->output); + i_stream_unref(&pump->input); + i_free(pump); } void iostream_pump_stop(struct iostream_pump *pump) diff --git a/src/lib/iostream-pump.h b/src/lib/iostream-pump.h index 21b68a625a..9b693038ef 100644 --- a/src/lib/iostream-pump.h +++ b/src/lib/iostream-pump.h @@ -48,7 +48,7 @@ void iostream_pump_start(struct iostream_pump *pump); void iostream_pump_stop(struct iostream_pump *pump); void iostream_pump_ref(struct iostream_pump *pump); -void iostream_pump_unref(struct iostream_pump **pump_r); +void iostream_pump_unref(struct iostream_pump **_pump); void iostream_pump_set_completion_callback(struct iostream_pump *pump, iostream_pump_callback_t *callback, void *context);