Fix memory leak (Overwrite repr without destroy)
authorsung.goo.kim <sung.goo.kim@samsung.com>
Thu, 5 Nov 2015 05:13:15 +0000 (14:13 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Tue, 10 Nov 2015 10:13:17 +0000 (19:13 +0900)
Change-Id: Ic5e182985b89ba4f46538597ff1623a208d38cfb

lib/icl-response.c

index a49bcdf..d7e1429 100644 (file)
@@ -116,11 +116,13 @@ API int iotcon_response_set_representation(iotcon_response_h resp,
                iotcon_interface_e iface, iotcon_representation_h repr)
 {
        RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
 
-       resp->repr = repr;
+       if (resp->repr)
+               iotcon_representation_destroy(resp->repr);
        resp->iface = iface;
-       icl_representation_inc_ref_count(resp->repr);
+       resp->repr = repr;
+       if (repr)
+               icl_representation_inc_ref_count(resp->repr);
 
        return IOTCON_ERROR_NONE;
 }