]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: iostream-pump: Make iostream_pump_unref() implementation match other similar...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 25 Feb 2018 18:13:18 +0000 (19:13 +0100)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 13 Jun 2018 08:30:30 +0000 (11:30 +0300)
This also means that iostream_pump_unref(NULL) is now a no-op.

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

index 9cc5b8896c608290b60a23e17e187a829d75b372..51ad8d040ae6da00bd08f75f82451db239cd495f 100644 (file)
@@ -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)
index 21b68a625a60d422127747e18c5173075f414e01..9b693038ef24dd2390878ee8e640ff743c7e64f7 100644 (file)
@@ -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);