mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-10 04:50:37 -04:00
Detect and handle more allocation failures.
This commit is contained in:
parent
0144886e7e
commit
666b096691
4
evdns.c
4
evdns.c
@ -3069,6 +3069,10 @@ search_request_new(struct evdns_base *base, struct evdns_request *handle,
|
|||||||
}
|
}
|
||||||
EVUTIL_ASSERT(handle->search_origname == NULL);
|
EVUTIL_ASSERT(handle->search_origname == NULL);
|
||||||
handle->search_origname = mm_strdup(name);
|
handle->search_origname = mm_strdup(name);
|
||||||
|
if (handle->search_origname == NULL) {
|
||||||
|
/* XXX Should we dealloc req? If yes, how? */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
handle->search_state = base->global_search_state;
|
handle->search_state = base->global_search_state;
|
||||||
handle->search_flags = flags;
|
handle->search_flags = flags;
|
||||||
base->global_search_state->refcount++;
|
base->global_search_state->refcount++;
|
||||||
|
7
evutil.c
7
evutil.c
@ -958,8 +958,13 @@ addrinfo_from_hostent(const struct hostent *ent,
|
|||||||
res = evutil_addrinfo_append(res, ai);
|
res = evutil_addrinfo_append(res, ai);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res && ((hints->ai_flags & EVUTIL_AI_CANONNAME) && ent->h_name))
|
if (res && ((hints->ai_flags & EVUTIL_AI_CANONNAME) && ent->h_name)) {
|
||||||
res->ai_canonname = mm_strdup(ent->h_name);
|
res->ai_canonname = mm_strdup(ent->h_name);
|
||||||
|
if (res->ai_canonname == NULL) {
|
||||||
|
evutil_freeaddrinfo(res);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
44
http.c
44
http.c
@ -2491,6 +2491,10 @@ evhttp_response_code(struct evhttp_request *req, int code, const char *reason)
|
|||||||
if (reason == NULL)
|
if (reason == NULL)
|
||||||
reason = evhttp_response_phrase_internal(code);
|
reason = evhttp_response_phrase_internal(code);
|
||||||
req->response_code_line = mm_strdup(reason);
|
req->response_code_line = mm_strdup(reason);
|
||||||
|
if (req->response_code_line == NULL) {
|
||||||
|
event_warn("%s: strdup", __func__);
|
||||||
|
/* XXX what else can we do? */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -3280,6 +3284,11 @@ evhttp_set_cb(struct evhttp *http, const char *uri,
|
|||||||
}
|
}
|
||||||
|
|
||||||
http_cb->what = mm_strdup(uri);
|
http_cb->what = mm_strdup(uri);
|
||||||
|
if (http_cb->what == NULL) {
|
||||||
|
event_warn("%s: strdup", __func__);
|
||||||
|
mm_free(http_cb);
|
||||||
|
return (-3);
|
||||||
|
}
|
||||||
http_cb->cb = cb;
|
http_cb->cb = cb;
|
||||||
http_cb->cbarg = cbarg;
|
http_cb->cbarg = cbarg;
|
||||||
|
|
||||||
@ -3911,6 +3920,10 @@ parse_authority(struct evhttp_uri *uri, char *s, char *eos)
|
|||||||
EVUTIL_ASSERT(eos);
|
EVUTIL_ASSERT(eos);
|
||||||
if (eos == s) {
|
if (eos == s) {
|
||||||
uri->host = mm_strdup("");
|
uri->host = mm_strdup("");
|
||||||
|
if (uri->host == NULL) {
|
||||||
|
event_warn("%s: strdup", __func__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3922,6 +3935,10 @@ parse_authority(struct evhttp_uri *uri, char *s, char *eos)
|
|||||||
return -1;
|
return -1;
|
||||||
*cp++ = '\0';
|
*cp++ = '\0';
|
||||||
uri->userinfo = mm_strdup(s);
|
uri->userinfo = mm_strdup(s);
|
||||||
|
if (uri->userinfo == NULL) {
|
||||||
|
event_warn("%s: strdup", __func__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
cp = s;
|
cp = s;
|
||||||
}
|
}
|
||||||
@ -3949,6 +3966,10 @@ parse_authority(struct evhttp_uri *uri, char *s, char *eos)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
uri->host = mm_malloc(eos-cp+1);
|
uri->host = mm_malloc(eos-cp+1);
|
||||||
|
if (uri->host == NULL) {
|
||||||
|
event_warn("%s: malloc", __func__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
memcpy(uri->host, cp, eos-cp);
|
memcpy(uri->host, cp, eos-cp);
|
||||||
uri->host[eos-cp] = '\0';
|
uri->host[eos-cp] = '\0';
|
||||||
return 0;
|
return 0;
|
||||||
@ -4039,7 +4060,10 @@ evhttp_uri_parse(const char *source_uri)
|
|||||||
if (token && scheme_ok(readp,token)) {
|
if (token && scheme_ok(readp,token)) {
|
||||||
*token = '\0';
|
*token = '\0';
|
||||||
uri->scheme = mm_strdup(readp);
|
uri->scheme = mm_strdup(readp);
|
||||||
|
if (uri->scheme == NULL) {
|
||||||
|
event_err(1, "%s: strdup", __func__);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
readp = token+1; /* eat : */
|
readp = token+1; /* eat : */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4096,11 +4120,25 @@ evhttp_uri_parse(const char *source_uri)
|
|||||||
|
|
||||||
EVUTIL_ASSERT(path);
|
EVUTIL_ASSERT(path);
|
||||||
uri->path = mm_strdup(path);
|
uri->path = mm_strdup(path);
|
||||||
|
if (uri->path == NULL) {
|
||||||
|
event_err(1, "%s: strdup", __func__);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
if (query)
|
if (query) {
|
||||||
uri->query = mm_strdup(query);
|
uri->query = mm_strdup(query);
|
||||||
if (fragment)
|
if (uri->query == NULL) {
|
||||||
|
event_err(1, "%s: strdup", __func__);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fragment) {
|
||||||
uri->fragment = mm_strdup(fragment);
|
uri->fragment = mm_strdup(fragment);
|
||||||
|
if (uri->fragment == NULL) {
|
||||||
|
event_err(1, "%s: strdup", __func__);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mm_free(readbuf);
|
mm_free(readbuf);
|
||||||
|
|
||||||
|
9
select.c
9
select.c
@ -99,7 +99,10 @@ select_init(struct event_base *base)
|
|||||||
if (!(sop = mm_calloc(1, sizeof(struct selectop))))
|
if (!(sop = mm_calloc(1, sizeof(struct selectop))))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
select_resize(sop, howmany(32 + 1, NFDBITS)*sizeof(fd_mask));
|
if (select_resize(sop, howmany(32 + 1, NFDBITS)*sizeof(fd_mask))) {
|
||||||
|
mm_free(sop);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
evsig_init(base);
|
evsig_init(base);
|
||||||
|
|
||||||
@ -198,8 +201,10 @@ select_resize(struct selectop *sop, int fdsz)
|
|||||||
if ((readset_in = mm_realloc(sop->event_readset_in, fdsz)) == NULL)
|
if ((readset_in = mm_realloc(sop->event_readset_in, fdsz)) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
sop->event_readset_in = readset_in;
|
sop->event_readset_in = readset_in;
|
||||||
if ((writeset_in = mm_realloc(sop->event_writeset_in, fdsz)) == NULL)
|
if ((writeset_in = mm_realloc(sop->event_writeset_in, fdsz)) == NULL) {
|
||||||
|
mm_free(readset_in);
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
sop->event_writeset_in = writeset_in;
|
sop->event_writeset_in = writeset_in;
|
||||||
sop->resize_out_sets = 1;
|
sop->resize_out_sets = 1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user