wl_screenshot: fix null pointer dereference 99/49299/2
authorBoram Park <boram1288.park@samsung.com>
Mon, 12 Oct 2015 10:57:51 +0000 (19:57 +0900)
committerGwanglim Lee <gl77.lee@samsung.com>
Mon, 12 Oct 2015 11:10:52 +0000 (04:10 -0700)
Change-Id: I1d35c115e0f207755f879f2454ee6cbe15fb38a3

src/modules/wl_screenshot/e_mod_main.c

index daa196eb86000f1a459a460ae3071ca796e38d9d..6d364ba0a890543eb070fb128df6c401644d0cd7 100644 (file)
@@ -115,6 +115,7 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
    char buff[PATH_MAX];
 
    inst = E_NEW(Instance, 1);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(inst, NULL);
 
    snprintf(buff, sizeof(buff), "%s/e-module-wl_screenshot.edj", _mod->dir);
 
@@ -124,6 +125,13 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
      edje_object_file_set(o, buff, "modules/wl_screenshot/main");
 
    gcc = e_gadcon_client_new(gc, name, id, style, o);
+   if (!gcc)
+     {
+        evas_object_del(o);
+        E_FREE(inst);
+        return NULL;
+     }
+
    gcc->data = inst;
 
    inst->gcc = gcc;
@@ -261,6 +269,8 @@ _create_shm_buffer(struct wl_shm *_shm, int width, int height, void **data_out)
 
    pool = wl_shm_create_pool(_shm, fd, size);
    close(fd);
+   if (!pool)
+     return NULL;
 
    buffer = 
      wl_shm_pool_create_buffer(pool, 0, width, height, stride,
@@ -324,11 +334,15 @@ _cb_timer(void *data __UNUSED__)
 
    /* FIXME: ow and oh should probably be the size of all outputs */
    buffer = _create_shm_buffer(ecore_wl_shm_get(), ow, oh, &d);
+   if (!buffer) return EINA_FALSE;
+
    screenshooter_shoot(_shooter, _output, buffer);
 
    ecore_wl_sync();
 
    _save_png(ow, oh, d);
 
+   wl_buffer_destroy(buffer);
+
    return EINA_FALSE;
 }