Skip to content

Commit

Permalink
lib: iostream-pump: Make iostream_pump_unref() implementation match o…
Browse files Browse the repository at this point in the history
…ther similar code.

This also means that iostream_pump_unref(NULL) is now a no-op.
  • Loading branch information
stephanbosch authored and cmouse committed Jun 13, 2018
1 parent 0f972d2 commit 3a8cf37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions src/lib/iostream-pump.c
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/iostream-pump.h
Expand Up @@ -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);
Expand Down

0 comments on commit 3a8cf37

Please sign in to comment.