Fix memory leak possibility for ip and port 76/124876/1
authorSeokHoon Lee <andy.shlee@samsung.com>
Thu, 13 Apr 2017 01:34:49 +0000 (10:34 +0900)
committerSeokHoon Lee <andy.shlee@samsung.com>
Thu, 13 Apr 2017 01:37:58 +0000 (10:37 +0900)
- When scmirroring_sink_set_ip_and_port called more than twice,
  memory leak occured.
- SCMIRRORING_ERROR_OUT_OF_MEMORY should returned if strdup failed.

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

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

index 39732e3b5a004a9e956caed6117b2ed4d713c04d..c20128305da9b081c33247d4f7375261031acc33 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-screen-mirroring
 Summary:    A screen mirroring library in Tizen C API
-Version:    0.1.71
+Version:    0.1.72
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 0299d48e7a9ca929ccf9e6032734906a87efcec7..a4d32a4a4eaf968556d0f34080231fdd2e9989a2 100644 (file)
@@ -158,8 +158,13 @@ int scmirroring_sink_set_ip_and_port(scmirroring_sink_h scmirroring_sink, const
 
        scmirroring_debug("ip[%s] port[%s]", ip, port);
 
+       SCMIRRORING_SAFE_FREE(handle->ip);
        handle->ip = strdup(ip);
+       scmirroring_retvm_if(handle->ip == NULL, SCMIRRORING_ERROR_OUT_OF_MEMORY, "Out of memory for ip");
+
+       SCMIRRORING_SAFE_FREE(handle->port);
        handle->port = strdup(port);
+       scmirroring_retvm_if(handle->port == NULL, SCMIRRORING_ERROR_OUT_OF_MEMORY, "Out of memory for port");
 
        scmirroring_debug_fleave();