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.9~2114 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b37d0e1004a257a618095b409a7a4bab15d23d92;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 dd53435f86..29129af469 100644 --- a/src/lib/iostream-pump.c +++ b/src/lib/iostream-pump.c @@ -169,19 +169,26 @@ void iostream_pump_ref(struct iostream_pump *pump) pump->refcount++; } -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->refcount > 0); - if (--pump->refcount == 0) { - iostream_pump_stop(pump); - o_stream_unref(&pump->output); - i_stream_unref(&pump->input); - i_free(pump); - } + + *_pump = NULL; + + if (--pump->refcount > 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 0614674e75..e0fd0eb53c 100644 --- a/src/lib/iostream-pump.h +++ b/src/lib/iostream-pump.h @@ -43,7 +43,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,