fix prevent 482200 ~ 482217
authorSangkwan Lee <skgood.lee@samsung.com>
Thu, 1 Oct 2015 07:24:23 +0000 (16:24 +0900)
committeryoungman <yman.jung@samsung.com>
Tue, 3 Nov 2015 11:08:20 +0000 (20:08 +0900)
Change-Id: Iec0b71761b2db17220126d13e12eeecd0cf715d0
Signed-off-by: Sangkwan Lee <skgood.lee@samsung.com>
daemon/icd-ioty.c
lib/icl-device.c
lib/icl-payload.c
lib/icl-resource.c
test/crud-test-client.c
test/device-test-server.c
test/repr-test-server.c

index dd52f98..7fc6886 100644 (file)
@@ -407,7 +407,7 @@ int icd_ioty_find_resource(const char *host_address, const char *resource_type,
        }
 
        if (IC_STR_EQUAL != strcmp(IC_STR_NULL, resource_type))
-               snprintf(uri + len, sizeof(uri), "?rt=%s", resource_type);
+               snprintf(uri + len, sizeof(uri) - len, "?rt=%s", resource_type);
 
        context = calloc(1, sizeof(icd_sig_ctx_s));
        if (NULL == context) {
@@ -468,10 +468,10 @@ static char* _icd_ioty_resource_generate_uri(char *uri_path, GVariant *query)
                DBG("query exist. key(%s), value(%s)", key, value);
 
                if (true == loop_first) {
-                       query_len = snprintf(uri_buf + len, sizeof(uri_buf), "?%s=%s", key, value);
+                       query_len = snprintf(uri_buf + len, sizeof(uri_buf) - len, "?%s=%s", key, value);
                        loop_first = false;
                } else {
-                       query_len = snprintf(uri_buf + len, sizeof(uri_buf), "&%s=%s", key, value);
+                       query_len = snprintf(uri_buf + len, sizeof(uri_buf) - len, "&%s=%s", key, value);
                }
 
                len += query_len;
@@ -534,7 +534,7 @@ static gboolean _icd_ioty_crud(int type, icDbus *object, GDBusMethodInvocation *
        GVariantIter *options;
        OCCallbackData cbdata = {0};
        int conn_type, options_size;
-       char *uri_path, *host, *uri, *dev_host, *ptr;
+       char *uri_path, *host, *uri, *dev_host, *ptr = NULL;
        OCHeaderOption oic_options[MAX_HEADER_OPTIONS];
        OCHeaderOption *oic_options_ptr = NULL;
        OCPayload *payload = NULL;
@@ -622,6 +622,7 @@ static gboolean _icd_ioty_crud(int type, icDbus *object, GDBusMethodInvocation *
        default:
                ERR("Invalid Connectivitiy Type");
                icd_ioty_complete_error(type, invocation, IOTCON_ERROR_IOTIVITY);
+               free(uri);
                return TRUE;
        }
 
@@ -681,7 +682,7 @@ OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type, GVarian
        icd_sig_ctx_s *context;
        OCCallbackData cbdata = {0};
        int conn_type, options_size;
-       char *uri_path, *host, *uri, *dev_host, *ptr;
+       char *uri_path, *host, *uri, *dev_host, *ptr = NULL;
        OCHeaderOption oic_options[MAX_HEADER_OPTIONS];
        OCHeaderOption *oic_options_ptr = NULL;
        OCConnectivityType oic_conn_type;
@@ -750,6 +751,9 @@ OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type, GVarian
                break;
        default:
                ERR("Invalid Connectivitiy Type");
+               free(context->bus_name);
+               free(context);
+               free(uri);
                return NULL;
        }
 
@@ -925,7 +929,7 @@ OCDoHandle icd_ioty_subscribe_presence(const char *host_address,
        }
 
        if (IC_STR_EQUAL != strcmp(IC_STR_NULL, resource_type))
-               snprintf(uri + len, sizeof(uri), "?rt=%s", resource_type);
+               snprintf(uri + len, sizeof(uri) - len, "?rt=%s", resource_type);
 
        context = calloc(1, sizeof(icd_sig_ctx_s));
        if (NULL == context) {
index 751686c..4b25012 100644 (file)
@@ -223,10 +223,16 @@ static void _icl_platform_info_cb(GDBusConnection *connection,
                gpointer user_data)
 {
        char *uri_path;
-       iotcon_platform_info_s *info = calloc(1, sizeof(iotcon_platform_info_s));
+       iotcon_platform_info_s *info = NULL;
        icl_platform_info_s *cb_container = user_data;
        iotcon_platform_info_cb cb = cb_container->cb;
 
+       info = calloc(1, sizeof(iotcon_platform_info_s));
+       if (NULL == info) {
+               ERR("calloc(client) Fail(%d)", errno);
+               return;
+       }
+
        g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s&s)",
                        &uri_path,
                        &info->platform_id,
@@ -245,6 +251,8 @@ static void _icl_platform_info_cb(GDBusConnection *connection,
 
        if (cb)
                cb(info, cb_container->user_data);
+
+       free(info);
 }
 
 
index f395151..f5608fe 100644 (file)
@@ -341,12 +341,15 @@ iotcon_representation_h icl_representation_from_gvariant(GVariant *var)
        ret = iotcon_state_create(&state);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_state_create() Fail(%d)", ret);
+               iotcon_representation_destroy(repr);
                return NULL;
        }
 
        ret = iotcon_representation_set_state(repr, state);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_representation_set_state() Fail(%d)", ret);
+               iotcon_state_destroy(state);
+               iotcon_representation_destroy(repr);
                return NULL;
        }
 
@@ -366,6 +369,8 @@ iotcon_representation_h icl_representation_from_gvariant(GVariant *var)
                        ERR("iotcon_resource_types_create() Fail(%d)", ret);
                        g_variant_iter_free(resource_types);
                        g_variant_iter_free(children);
+                       iotcon_state_destroy(state);
+                       iotcon_representation_destroy(repr);
                        return NULL;
                }
 
@@ -384,5 +389,7 @@ iotcon_representation_h icl_representation_from_gvariant(GVariant *var)
        }
        g_variant_iter_free(children);
 
+       iotcon_state_destroy(state);
+
        return repr;
 }
index 4c0e5bf..2b91906 100644 (file)
@@ -93,6 +93,8 @@ static void _icl_request_handler(GDBusConnection *connection,
                        ERR("iotcon_query_create() Fail(%d)", ret);
                        g_variant_iter_free(query);
                        g_variant_iter_free(repr_iter);
+                       if (request.header_options)
+                               iotcon_options_destroy(request.header_options);
                        return;
                }
 
index 28efa78..7c9b481 100644 (file)
@@ -164,6 +164,7 @@ static void _on_get(iotcon_client_h resource, iotcon_representation_h recv_repr,
        ret = iotcon_state_create(&send_state);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_state_create() Fail(%d)", ret);
+               iotcon_representation_destroy(send_repr);
                return;
        }
 
@@ -174,6 +175,7 @@ static void _on_get(iotcon_client_h resource, iotcon_representation_h recv_repr,
        /* send PUT request */
        iotcon_put(resource, send_repr, NULL, _on_put, NULL);
 
+       iotcon_state_destroy(send_state);
        iotcon_representation_destroy(send_repr);
 }
 
index 55f2072..71cb979 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <stdlib.h>
 #include <glib.h>
 #include <iotcon.h>
 #include "test.h"
@@ -26,6 +27,10 @@ int main()
        char *device_name;
 
        iotcon_platform_info_s *platform_info = calloc(1, sizeof(iotcon_platform_info_s));
+       if (NULL == platform_info) {
+               ERR("calloc() Fail(%d)", errno);
+               return -1;
+       }
 
        platform_info->platform_id = "platform_id";
        platform_info->manuf_name = "manuf_name";
@@ -49,9 +54,12 @@ int main()
        ret = iotcon_register_platform_info(platform_info);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_register_platform_info() Fail(%d)", ret);
+               free(platform_info);
                return -1;
        }
 
+       free(platform_info);
+
        ret = iotcon_register_device_info(device_name);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_register_platform_info() Fail(%d)", ret);
index c097356..f49f190 100644 (file)
@@ -101,6 +101,8 @@ static void _room_request_handler_get(iotcon_request_h request,
        ret = iotcon_list_create(IOTCON_TYPE_INT, &temperature_list);
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon_list_create() Fail(%d)", ret);
+               iotcon_state_destroy(room_state);
+               iotcon_representation_destroy(room_repr);
                return;
        }