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 2870316171709bfc06b634740e121b16bc805d72..bdbd88de667a082a9cb8078daf1ae18cbf4c68ba 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 ceab37a61437a4f90902a100c3cdf8a46148835e..15ec0f432ec9d8a70d11b183a8bd684e8d4734be 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);