efl_ui_selection_manager: Don't leak malloc'd data
authorChristopher Michael <cp.michael@samsung.com>
Mon, 1 Apr 2019 14:02:57 +0000 (10:02 -0400)
committerJunsuChoi <jsuya.choi@samsung.com>
Tue, 2 Apr 2019 04:24:22 +0000 (13:24 +0900)
Summary:
Coverity reports that we potentially leak char *s here. If we do not
have 'data_ret', then the malloc'd 's' sould be freed as we are not
going to use it.

Fixes Coverity CID1396949

@fix

Reviewers: raster, cedric, bu5hm4n, zmike

Reviewed By: bu5hm4n

Subscribers: #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D8523

src/lib/elementary/efl_ui_selection_manager.c

index 98926c0..c0a79dd 100644 (file)
@@ -1155,15 +1155,20 @@ static Eina_Bool
 _x11_vcard_send(char *target EINA_UNUSED, void *data EINA_UNUSED, int size EINA_UNUSED, void **data_ret, int *size_ret, Ecore_X_Atom *ttype EINA_UNUSED, int *typesize EINA_UNUSED)
 {
    Sel_Manager_Selection *sel;
-   char *s;
 
    sel_debug("Vcard send called");
    sel = *(Sel_Manager_Selection **)data;
-   s = malloc(sel->data.len + 1);
-   if (!s) return EINA_FALSE;
-   memcpy(s, sel->data.mem, sel->data.len);
-   s[sel->data.len] = 0;
-   if (data_ret) *data_ret = s;
+   if (data_ret)
+     {
+        char *s;        
+
+        s = malloc(sel->data.len + 1);
+        if (!s) return EINA_FALSE;
+        memcpy(s, sel->data.mem, sel->data.len);
+        s[sel->data.len] = 0;
+        *data_ret = s;
+     }
+
    if (size_ret) *size_ret = sel->data.len;
    return EINA_TRUE;
 }