summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-12-10 08:01:16 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-12-10 08:01:16 +0000
commitb4fcd423c987fdaec11cdc1028a7812fa0173a51 (patch)
treea464106e1c75932f42a1ed5791087335b33e95af
parent19e0897703e226a9ba1f2e8b6a4e41be878ef394 (diff)
elementary: correctly check error in elm_cnp.
SVN revision: 80576
-rw-r--r--ChangeLog1
-rw-r--r--NEWS1
-rw-r--r--src/lib/elm_cnp.c38
3 files changed, 18 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index ee9385211..81171230d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -800,3 +800,4 @@
8002012-12-10 Cedric Bail 8002012-12-10 Cedric Bail
801 801
802 * Make sure private data is not NULL in elm_interface_scrollable. 802 * Make sure private data is not NULL in elm_interface_scrollable.
803 * Correctly handle failure case in _x11_notify_handler_image.
diff --git a/NEWS b/NEWS
index fc2838c43..08b3dd2c7 100644
--- a/NEWS
+++ b/NEWS
@@ -87,6 +87,7 @@ Fixes:
87 * Simplify test in elm_entry_text_set. 87 * Simplify test in elm_entry_text_set.
88 * Fix focus problem in multibuttonentry. Entry can get focus only when multibuttonentry is focused. 88 * Fix focus problem in multibuttonentry. Entry can get focus only when multibuttonentry is focused.
89 * Make sure private data is not NULL in elm_interface_scrollable. 89 * Make sure private data is not NULL in elm_interface_scrollable.
90 * Correctly handle failure case in _x11_notify_handler_image.
90 91
91Removals: 92Removals:
92 93
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index 22e3a225e..7dee220ae 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -830,6 +830,7 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
830 } 830 }
831 /* generate tmp name */ 831 /* generate tmp name */
832 tmp = _tempfile_new(data->length); 832 tmp = _tempfile_new(data->length);
833 if (!tmp) return 0;
833 memcpy(tmp->map, data->data, data->length); 834 memcpy(tmp->map, data->data, data->length);
834 munmap(tmp->map, data->length); 835 munmap(tmp->map, data->length);
835 /* FIXME: Add to paste image data to clean up */ 836 /* FIXME: Add to paste image data to clean up */
@@ -1880,22 +1881,15 @@ _tempfile_new(int size)
1880 tmppath = getenv("TMP"); 1881 tmppath = getenv("TMP");
1881 if (!tmppath) tmppath = P_tmpdir; 1882 if (!tmppath) tmppath = P_tmpdir;
1882 len = snprintf(NULL, 0, "%s/%sXXXXXX", tmppath, "elmcnpitem-"); 1883 len = snprintf(NULL, 0, "%s/%sXXXXXX", tmppath, "elmcnpitem-");
1883 if (len < 0) 1884 if (len < 0) goto on_error;
1884 {
1885 free(info);
1886 return NULL;
1887 }
1888 len++; 1885 len++;
1889 info->filename = malloc(len); 1886 info->filename = malloc(len);
1890 if (!info->filename) 1887 if (!info->filename) goto on_error;
1891 {
1892 free(info);
1893 return NULL;
1894 }
1895 snprintf(info->filename,len,"%s/%sXXXXXX", tmppath, "elmcnpitem-"); 1888 snprintf(info->filename,len,"%s/%sXXXXXX", tmppath, "elmcnpitem-");
1896 cur_umask = umask(S_IRWXO | S_IRWXG); 1889 cur_umask = umask(S_IRWXO | S_IRWXG);
1897 info->fd = mkstemp(info->filename); 1890 info->fd = mkstemp(info->filename);
1898 umask(cur_umask); 1891 umask(cur_umask);
1892 if (info->fd < 0) goto on_error;
1899# ifdef __linux__ 1893# ifdef __linux__
1900 { 1894 {
1901 char *tmp; 1895 char *tmp;
@@ -1917,30 +1911,30 @@ _tempfile_new(int size)
1917 } 1911 }
1918# endif 1912# endif
1919 cnp_debug("filename is %s\n", info->filename); 1913 cnp_debug("filename is %s\n", info->filename);
1920 if (size < 1) 1914 if (size < 1) goto on_error;
1921 {
1922 /* Set map to NULL and return */
1923 info->map = NULL;
1924 info->len = 0;
1925 return info;
1926 }
1927 /* Map it in */ 1915 /* Map it in */
1928 if (ftruncate(info->fd, size)) 1916 if (ftruncate(info->fd, size))
1929 { 1917 {
1930 perror("ftruncate"); 1918 perror("ftruncate");
1931 info->map = NULL; 1919 goto on_error;
1932 info->len = 0;
1933 return info;
1934 } 1920 }
1935 eina_mmap_safety_enabled_set(EINA_TRUE); 1921 eina_mmap_safety_enabled_set(EINA_TRUE);
1936 info->map = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, info->fd, 0); 1922 info->map = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, info->fd, 0);
1937 if (info->map == MAP_FAILED) 1923 if (info->map == MAP_FAILED)
1938 { 1924 {
1939 perror("mmap"); 1925 perror("mmap");
1940 info->map = NULL; 1926 goto on_error;
1941 info->len = 0;
1942 } 1927 }
1943 return info; 1928 return info;
1929
1930 on_error:
1931 if (info->fd >= 0) close(info->fd);
1932 info->fd = -1;
1933 /* Set map to NULL and return */
1934 info->map = NULL;
1935 info->len = 0;
1936 free(info);
1937 return NULL;
1944#else 1938#else
1945 (void) size; 1939 (void) size;
1946 return NULL; 1940 return NULL;