Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-06-21 18:19:10 +0300
committerFelix Fietkau <nbd@nbd.name>2016-06-26 13:53:51 +0300
commit1f019ceea1ed39286e6bccfb3ff936c22fe0f7c0 (patch)
tree92ec3e71ca90b1bb12ff930ac1b7abfa8c1d0e07 /ustream.c
parentc2f2c47f3e9a2d709ec82a79f6fadd3124c18781 (diff)
Fix various memory management issues
Consistently handle allocation failures. Some functions are changed to return bool or int instead of void to allow returning an error. Also fix a buffer size miscalculation in lua/uloop and use _exit() instead of exit() on errors after forking. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Diffstat (limited to 'ustream.c')
-rw-r--r--ustream.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/ustream.c b/ustream.c
index e7ee9f0..d36ce08 100644
--- a/ustream.c
+++ b/ustream.c
@@ -65,6 +65,9 @@ static int ustream_alloc_default(struct ustream *s, struct ustream_buf_list *l)
return -1;
buf = malloc(sizeof(*buf) + l->buffer_len + s->string_data);
+ if (!buf)
+ return -1;
+
ustream_init_buf(buf, l->buffer_len);
ustream_add_buf(l, buf);
@@ -490,6 +493,8 @@ int ustream_vprintf(struct ustream *s, const char *format, va_list arg)
return ustream_write_buffered(s, buf, maxlen, wr);
} else {
buf = malloc(maxlen + 1);
+ if (!buf)
+ return 0;
wr = vsnprintf(buf, maxlen + 1, format, arg);
wr = ustream_write(s, buf, wr, false);
free(buf);
@@ -517,6 +522,8 @@ int ustream_vprintf(struct ustream *s, const char *format, va_list arg)
return wr;
buf = malloc(maxlen + 1);
+ if (!buf)
+ return wr;
maxlen = vsnprintf(buf, maxlen + 1, format, arg);
wr = ustream_write_buffered(s, buf + wr, maxlen - wr, wr);
free(buf);