mirror of
https://github.com/cuberite/libevent.git
synced 2025-08-05 10:16:08 -04:00
Fix leaks in error path of the bufferevent_init_common_()
(cherry picked from commit 6995b9a864c16bcb84ea0f7a2cf856143020316b)
This commit is contained in:
parent
b6724b6059
commit
bb0f8fe7d5
@ -315,14 +315,12 @@ bufferevent_init_common_(struct bufferevent_private *bufev_private,
|
|||||||
|
|
||||||
if (!bufev->input) {
|
if (!bufev->input) {
|
||||||
if ((bufev->input = evbuffer_new()) == NULL)
|
if ((bufev->input = evbuffer_new()) == NULL)
|
||||||
return -1;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bufev->output) {
|
if (!bufev->output) {
|
||||||
if ((bufev->output = evbuffer_new()) == NULL) {
|
if ((bufev->output = evbuffer_new()) == NULL)
|
||||||
evbuffer_free(bufev->input);
|
goto err;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bufev_private->refcnt = 1;
|
bufev_private->refcnt = 1;
|
||||||
@ -334,7 +332,8 @@ bufferevent_init_common_(struct bufferevent_private *bufev_private,
|
|||||||
|
|
||||||
bufev->be_ops = ops;
|
bufev->be_ops = ops;
|
||||||
|
|
||||||
bufferevent_ratelim_init_(bufev_private);
|
if (bufferevent_ratelim_init_(bufev_private))
|
||||||
|
goto err;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set to EV_WRITE so that using bufferevent_write is going to
|
* Set to EV_WRITE so that using bufferevent_write is going to
|
||||||
@ -345,20 +344,14 @@ bufferevent_init_common_(struct bufferevent_private *bufev_private,
|
|||||||
|
|
||||||
#ifndef EVENT__DISABLE_THREAD_SUPPORT
|
#ifndef EVENT__DISABLE_THREAD_SUPPORT
|
||||||
if (options & BEV_OPT_THREADSAFE) {
|
if (options & BEV_OPT_THREADSAFE) {
|
||||||
if (bufferevent_enable_locking_(bufev, NULL) < 0) {
|
if (bufferevent_enable_locking_(bufev, NULL) < 0)
|
||||||
/* cleanup */
|
goto err;
|
||||||
evbuffer_free(bufev->input);
|
|
||||||
evbuffer_free(bufev->output);
|
|
||||||
bufev->input = NULL;
|
|
||||||
bufev->output = NULL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if ((options & (BEV_OPT_DEFER_CALLBACKS|BEV_OPT_UNLOCK_CALLBACKS))
|
if ((options & (BEV_OPT_DEFER_CALLBACKS|BEV_OPT_UNLOCK_CALLBACKS))
|
||||||
== BEV_OPT_UNLOCK_CALLBACKS) {
|
== BEV_OPT_UNLOCK_CALLBACKS) {
|
||||||
event_warnx("UNLOCK_CALLBACKS requires DEFER_CALLBACKS");
|
event_warnx("UNLOCK_CALLBACKS requires DEFER_CALLBACKS");
|
||||||
return -1;
|
goto err;
|
||||||
}
|
}
|
||||||
if (options & BEV_OPT_UNLOCK_CALLBACKS)
|
if (options & BEV_OPT_UNLOCK_CALLBACKS)
|
||||||
event_deferred_cb_init_(
|
event_deferred_cb_init_(
|
||||||
@ -379,6 +372,17 @@ bufferevent_init_common_(struct bufferevent_private *bufev_private,
|
|||||||
evbuffer_set_parent_(bufev->output, bufev);
|
evbuffer_set_parent_(bufev->output, bufev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err:
|
||||||
|
if (bufev->input) {
|
||||||
|
evbuffer_free(bufev->input);
|
||||||
|
bufev->input = NULL;
|
||||||
|
}
|
||||||
|
if (bufev->output) {
|
||||||
|
evbuffer_free(bufev->output);
|
||||||
|
bufev->output = NULL;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user