Fix some memory leak possibility 54/125354/2
authorSeokHoon Lee <andy.shlee@samsung.com>
Mon, 17 Apr 2017 05:41:55 +0000 (14:41 +0900)
committerSeokHoon Lee <andy.shlee@samsung.com>
Mon, 17 Apr 2017 05:45:39 +0000 (14:45 +0900)
- Null check before strdup for ip and port
- ERROR_OUT_OF_MEMORY should return
   when it failed to strdup for server name

Signed-off-by: SeokHoon Lee <andy.shlee@samsung.com>
Change-Id: I358d052a6f0e4729d817915e99e908abd8f8f1da

packaging/capi-media-screen-mirroring.spec
src/scmirroring_src.c

index bd6c0f209caaa5cc11bcf8417bd8bdfb49ab64a4..85fb20f2a5c4b4ec441924c2b946e7f7c5b6fc0b 100644 (file)
@@ -1,7 +1,7 @@
 Name:       capi-media-screen-mirroring
 Summary:    A screen mirroring library in Tizen C API
-Version:    0.1.74
-Release:    1
+Version:    0.1.75
+Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index 21267615664e06c0021ab19d71c5b49b6da2f481..d73ddcbccb78357062195b25644d64a85cca98cb 100644 (file)
@@ -532,13 +532,13 @@ int scmirroring_src_set_ip_and_port(scmirroring_src_h scmirroring, const char *i
        scmirroring_retvm_if(!STRING_VALID(ip), SCMIRRORING_ERROR_INVALID_PARAMETER, "INVALID IP");
        scmirroring_retvm_if(!STRING_VALID(port), SCMIRRORING_ERROR_INVALID_PARAMETER, "INVALID PORT");
 
+       SCMIRRORING_SAFE_FREE(_scmirroring->ip);
        _scmirroring->ip = strdup(ip);
-       _scmirroring->port = strdup(port);
+       scmirroring_retvm_if(_scmirroring->ip == NULL, SCMIRRORING_ERROR_OUT_OF_MEMORY, "Out of memory for IP");
 
-       if ((_scmirroring->ip == NULL) || (_scmirroring->port == NULL)) {
-               scmirroring_error("OUT_OF_MEMORY");
-               return SCMIRRORING_ERROR_OUT_OF_MEMORY;
-       }
+       SCMIRRORING_SAFE_FREE(_scmirroring->port);
+       _scmirroring->port = strdup(port);
+       scmirroring_retvm_if(_scmirroring->port == NULL, SCMIRRORING_ERROR_OUT_OF_MEMORY, "Out of memory for PORT");
 
        if (_scmirroring->connected)
                ret = __scmirroring_src_send_set_ip(_scmirroring);
@@ -589,8 +589,9 @@ int scmirroring_src_set_server_name(scmirroring_src_h scmirroring, const char *n
        scmirroring_retvm_if(_scmirroring == NULL, SCMIRRORING_ERROR_INVALID_PARAMETER, "Handle is NULL");
        scmirroring_retvm_if(_scmirroring->magic_num != SCMIRRORING_MAGIC_NUMBER, SCMIRRORING_ERROR_INVALID_PARAMETER, "Invalid handle");
 
-       if (_scmirroring->server_name) g_free(_scmirroring->server_name);
+       SCMIRRORING_SAFE_G_FREE(_scmirroring->server_name);
        _scmirroring->server_name = g_strdup(name);
+       scmirroring_retvm_if(_scmirroring->server_name == NULL, SCMIRRORING_ERROR_OUT_OF_MEMORY, "Out of memory for server name");
 
        scmirroring_debug_fleave();