mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-10 16:31:44 +00:00
Handle case of malloc failure in mbuf_resize
PUBLISHED_FROM=0cb98ac520b8aeb8bbeb2f23b8c65c62ab256021
This commit is contained in:
1 parent
1a6bc7c514
commit
e34747d1ad
1 file changed
+7
-5
+7
-5
@@ -144,13 +144,15 @@ void mbuf_free(struct mbuf *mbuf) {
|
|||||||
|
|
||||||
void mbuf_resize(struct mbuf *a, size_t new_size) {
|
void mbuf_resize(struct mbuf *a, size_t new_size) {
|
||||||
if (new_size > a->size || (new_size < a->size && new_size >= a->len)) {
|
if (new_size > a->size || (new_size < a->size && new_size >= a->len)) {
|
||||||
a->buf = (char *) MBUF_REALLOC(a->buf, new_size);
|
char *buf = (char *) MBUF_REALLOC(a->buf, new_size);
|
||||||
/*
|
/*
|
||||||
* In case realloc fails, there's not much we can do except set size to 0.
|
* In case realloc fails, there's not much we can do, except keep things as
|
||||||
* Note that NULL is a valid return value from realloc when size == 0, but
|
* they are. Note that NULL is a valid return value from realloc when
|
||||||
* that is covered too.
|
* size == 0, but that is covered too.
|
||||||
*/
|
*/
|
||||||
a->size = (a->buf != NULL ? new_size : 0);
|
if (buf == NULL && new_size != 0) return;
|
||||||
|
a->buf = buf;
|
||||||
|
a->size = new_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user