mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-19 19:40:56 +00:00
Add error check for iobuf allocation
This commit is contained in:
1 parent
6678e36278
commit
86b1053678
6 files changed
+33
-17
No files matched your search
+12
-5
@@ -1195,7 +1195,8 @@ struct mg_connection *mg_http_listen(struct mg_mgr *mgr, const char *url,
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
|
||||
int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
|
||||
int ok = 1;
|
||||
if (new_size == 0) {
|
||||
free(io->buf);
|
||||
io->buf = NULL;
|
||||
@@ -1210,16 +1211,20 @@ void mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
|
||||
io->buf = (unsigned char *) p;
|
||||
io->size = new_size;
|
||||
} else {
|
||||
ok = 0;
|
||||
LOG(LL_ERROR,
|
||||
("%lu->%lu", (unsigned long) io->size, (unsigned long) new_size));
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
void mg_iobuf_init(struct mg_iobuf *io, size_t size) {
|
||||
int mg_iobuf_init(struct mg_iobuf *io, size_t size) {
|
||||
int ok = 1;
|
||||
io->buf = NULL;
|
||||
io->len = io->size = 0;
|
||||
if (size > 0) mg_iobuf_resize(io, size);
|
||||
if (size > 0) ok = mg_iobuf_resize(io, size);
|
||||
return ok;
|
||||
}
|
||||
|
||||
size_t mg_iobuf_append(struct mg_iobuf *io, const void *buf, size_t len,
|
||||
@@ -2622,6 +2627,7 @@ int mg_send(struct mg_connection *c, const void *buf, size_t len) {
|
||||
int fail, n = c->is_udp
|
||||
? ll_write(c, buf, (SOCKET) len, &fail)
|
||||
: (int) mg_iobuf_append(&c->send, buf, len, MG_IO_SIZE);
|
||||
if (len > 0 && n == 0) fail = 1;
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -2696,8 +2702,9 @@ static void read_conn(struct mg_connection *c,
|
||||
// NOTE(lsm): do only one iteration of reads, cause some systems
|
||||
// (e.g. FreeRTOS stack) return 0 instead of -1/EWOULDBLOCK when no data
|
||||
if (c->recv.size - c->recv.len < MG_IO_SIZE &&
|
||||
c->recv.size < MG_MAX_RECV_BUF_SIZE) {
|
||||
mg_iobuf_resize(&c->recv, c->recv.size + MG_IO_SIZE);
|
||||
c->recv.size < MG_MAX_RECV_BUF_SIZE &&
|
||||
!mg_iobuf_resize(&c->recv, c->recv.size + MG_IO_SIZE)) {
|
||||
c->is_closing = 1;
|
||||
}
|
||||
buf = c->recv.buf + c->recv.len;
|
||||
len = (int) (c->recv.size - c->recv.len);
|
||||
|
||||
Reference in new issue
Block a user