elementary: correctly check error in elm_cnp.
authorCedric BAIL <cedric.bail@free.fr>
Mon, 10 Dec 2012 08:01:16 +0000 (08:01 +0000)
committerCedric BAIL <cedric.bail@free.fr>
Mon, 10 Dec 2012 08:01:16 +0000 (08:01 +0000)
SVN revision: 80576

ChangeLog
NEWS
src/lib/elm_cnp.c

index ee93852..8117123 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 2012-12-10  Cedric Bail
 
        * Make sure private data is not NULL in elm_interface_scrollable.
+       * Correctly handle failure case in _x11_notify_handler_image.
diff --git a/NEWS b/NEWS
index fc2838c..08b3dd2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -87,6 +87,7 @@ Fixes:
    * Simplify test in elm_entry_text_set.
    * Fix focus problem in multibuttonentry. Entry can get focus only when multibuttonentry is focused.
    * Make sure private data is not NULL in elm_interface_scrollable.
+   * Correctly handle failure case in _x11_notify_handler_image.
 
 Removals:
 
index 22e3a22..7dee220 100644 (file)
@@ -830,6 +830,7 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
      }
    /* generate tmp name */
    tmp = _tempfile_new(data->length);
+   if (!tmp) return 0;
    memcpy(tmp->map, data->data, data->length);
    munmap(tmp->map, data->length);
    /* FIXME: Add to paste image data to clean up */
@@ -1880,22 +1881,15 @@ _tempfile_new(int size)
    tmppath = getenv("TMP");
    if (!tmppath) tmppath = P_tmpdir;
    len = snprintf(NULL, 0, "%s/%sXXXXXX", tmppath, "elmcnpitem-");
-   if (len < 0)
-     {
-        free(info);
-        return NULL;
-     }
+   if (len < 0) goto on_error;
    len++;
    info->filename = malloc(len);
-   if (!info->filename)
-     {
-        free(info);
-        return NULL;
-     }
+   if (!info->filename) goto on_error;
    snprintf(info->filename,len,"%s/%sXXXXXX", tmppath, "elmcnpitem-");
    cur_umask = umask(S_IRWXO | S_IRWXG);
    info->fd = mkstemp(info->filename);
    umask(cur_umask);
+   if (info->fd < 0) goto on_error;
 # ifdef __linux__
      {
         char *tmp;
@@ -1917,30 +1911,30 @@ _tempfile_new(int size)
      }
 # endif
    cnp_debug("filename is %s\n", info->filename);
-   if (size < 1)
-     {
-        /* Set map to NULL and return */
-        info->map = NULL;
-        info->len = 0;
-        return info;
-     }
+   if (size < 1) goto on_error;
    /* Map it in */
    if (ftruncate(info->fd, size))
      {
         perror("ftruncate");
-        info->map = NULL;
-        info->len = 0;
-        return info;
+        goto on_error;
      }
    eina_mmap_safety_enabled_set(EINA_TRUE);
    info->map = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, info->fd, 0);
    if (info->map == MAP_FAILED)
      {
         perror("mmap");
-        info->map = NULL;
-        info->len = 0;
+        goto on_error;
      }
    return info;
+
+ on_error:
+   if (info->fd >= 0) close(info->fd);
+   info->fd = -1;
+   /* Set map to NULL and return */
+   info->map = NULL;
+   info->len = 0;
+   free(info);
+   return NULL;
 #else
    (void) size;
    return NULL;