check oom on lws_malloc
authorAndy Green <andy@warmcat.com>
Thu, 12 May 2016 13:54:29 +0000 (21:54 +0800)
committerAndy Green <andy@warmcat.com>
Thu, 12 May 2016 13:54:29 +0000 (21:54 +0800)
Signed-off-by: Andy Green <andy@warmcat.com>
lib/libuv.c
lib/service.c

index 2870316..bdbd88d 100644 (file)
@@ -151,6 +151,10 @@ lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, uv_signal_cb cb,
 
        if (!loop) {
                loop = lws_malloc(sizeof(*loop));
+               if (!loop) {
+                       lwsl_err("OOM\n");
+                       return -1;
+               }
                uv_loop_init(loop);
                pt->ev_loop_foreign = 0;
        } else
index ceab37a..15ec0f4 100644 (file)
@@ -349,6 +349,8 @@ int lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len)
        /* a new rxflow, buffer it and warn caller */
        lwsl_info("new rxflow input buffer len %d\n", len - n);
        wsi->rxflow_buffer = lws_malloc(len - n);
+       if (!wsi->rxflow_buffer)
+               return -1;
        wsi->rxflow_len = len - n;
        wsi->rxflow_pos = 0;
        memcpy(wsi->rxflow_buffer, buf + n, len - n);