Fix memory leak for location API's 98/260398/2
authorAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 24 May 2021 10:48:41 +0000 (16:18 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Fri, 25 Jun 2021 12:03:12 +0000 (17:33 +0530)
Change-Id: Iad60d957970254dbe3122ff3071bcd31faf3681d
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/user-awareness-internal-type.h
include/user-awareness-internal.h
include/user-awareness-util.h
src/user-awareness-event-handler.c
src/user-awareness-monitors.c
src/user-awareness-util.c
tests/test/uat-scenarios.c

index e627a1b1a4d0a4a74c663814853adc4ef8df60ee..48a99b6a9932ec2a52f4472619d1d1d0ed23e7a3 100755 (executable)
@@ -72,6 +72,8 @@ typedef bool (*ua_registered_user_cb)(
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
  * @brief Callback to be invoked on detection of user and device location.
+ * Callback to be invoked once for each user/device in location callback
+ * period set by ua_monitor_set_location_period()
  * @since_tizen 6.5
  *
  * @remarks The @a monitor handle should not be released.
@@ -102,6 +104,7 @@ typedef bool (*ua_registered_user_cb)(
  * @param[in] location The location handle.
  * @param[in] user_data The user data passed in ua_monitor_start_location_detection()
  *
+ * @see ua_monitor_set_location_period()
  * @see ua_monitor_start_location_detection()
  */
 typedef void (*ua_location_detected_cb)(
@@ -115,7 +118,6 @@ typedef void (*ua_location_detected_cb)(
                ua_location_h location,
                void *user_data);
 
-
 /**
  * @}
  */
index 2296f8d5de0fd4c17d6d044b9e53e3cca3536fd9..69108c7a3fe97d76af3dd744e82335576691acdb 100755 (executable)
@@ -370,6 +370,7 @@ int ua_service_get_device_discriminant(
  * @retval #UA_ERROR_NOT_SUPPORTED Not Supported
  *
  * @see ua_location_detected_cb()
+ * @see ua_monitor_set_location_period()
  * @see ua_monitor_stop_location_detection()
  */
 int ua_monitor_start_location_detection(
@@ -438,7 +439,9 @@ int ua_location_get_position(ua_location_h location_handle,
 /**
  * @internal
  * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Sets the location period.
+ * @brief Sets the location callback period in milli-seconds.
+ * If location period is not set, it will be automatically
+ * set to #UA_LOCATION_PERIOD_DEFAULT
  * @since_tizen 6.5
  *
  * @param[in] monitor handle
index 04e695307fa0c264c6b7ab3511b00277879bdc3a..14e61084e12a0931e623b22e61959f4f8ad75a27 100755 (executable)
@@ -189,7 +189,7 @@ ua_sensor_type_e _ua_dev_type_to_sensor(ua_mac_type_e type);
  * @post
  *
  */
- ua_mac_type_e _ua_sensor_to_dev_type(ua_sensor_type_e type);
+ua_mac_type_e _ua_sensor_to_dev_type(ua_sensor_type_e type);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
@@ -334,6 +334,16 @@ int _ua_free_sensor_info(ua_sensor_info_s *sensor_info);
  */
 void _ua_clear_sensor_list(void);
 
+/**
+ * @brief Clears location handle list.
+ * @since_tizen 6.5
+ *
+ * @exception
+ * @pre
+ * @post
+ */
+void _ua_clear_location_list(void);
+
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
  * @brief Updates location info.
index 053ad57ceecdc68db801d76451c8503ad12954f9..7cc47e55dabf13a66d7f405d3ffb35d4f8fcc521 100755 (executable)
@@ -33,6 +33,7 @@ static void __ua_cleanup(void)
        _ua_clear_user_list();
        _ua_clear_device_list();
        _ua_clear_sensor_list();
+       _ua_clear_location_list();
 }
 
 /* LCOV_EXCL_START */
index a7d9d3f826bd060c55b1c28e4a4f548666abc725..35d0edcf81191968d5789d99d67d243c19469eca 100755 (executable)
@@ -1827,10 +1827,10 @@ int ua_monitor_start_location_detection(
 
        /* Start timer */
        if (0 == location_cb_timer) {
-               UA_INFO("Location detection started, start timer of %d seconds",
-                                               (monitor->location_period)/1000);
-               location_cb_timer = g_timeout_add_seconds(
-                       (monitor->location_period)/1000,
+               UA_INFO("Location detection started, start timer of "
+                       "%d milli-seconds", (monitor->location_period));
+               location_cb_timer = g_timeout_add(
+                       monitor->location_period,
                        _ua_monitor_send_location_cb, service_handle);
        }
 
@@ -1966,8 +1966,10 @@ int ua_monitor_stop_location_detection(ua_monitor_h handle)
        monitor->location_detection_started = FALSE;
        monitor->location_detected_bitmask = 0;
 
-       if (location_cb_timer)
+       if (0 != location_cb_timer) {
                g_source_remove(location_cb_timer);
+               location_cb_timer = 0;
+       }
 
        FUNC_EXIT;
        return UA_ERROR_NONE;
@@ -2033,7 +2035,6 @@ int ua_monitor_set_location_period(
        return UA_ERROR_NONE;
 }
 
-
 int ua_monitor_set_brightness_threshold(ua_monitor_h handle,
        int presence_threshold, int absence_threshold)
 {
index 2f950d81b82f1c12172623bd1d371b795ea76348..0c75de95a541c06ffb1140232891ed62dc2d840b 100755 (executable)
@@ -643,3 +643,20 @@ gboolean _ua_monitor_send_location_cb(gpointer data)
        FUNC_EXIT;
        return TRUE;
 }
+
+static void __ua_free_ua_location_info_s(gpointer data)
+{
+       FUNC_ENTRY;
+       ua_location_info_s *location_info = (ua_location_info_s*)data;
+
+       if (!location_info)
+               return;
+       g_free(location_info);
+       FUNC_EXIT;
+}
+
+void _ua_clear_location_list(void)
+{
+       g_slist_free_full(ua_location_list, __ua_free_ua_location_info_s);
+       ua_location_list = NULL;
+}
index 8397dfb73c86f5c85d82a6feab31007f5bbcce96..148d6b6446e7486e77ef46219f34104f02506c5c 100755 (executable)
@@ -433,7 +433,7 @@ static int run_ua_monitor_start_location_detection(
 
        check_if(NULL == g_ua_mon_h);
 
-       ret = ua_monitor_set_location_period(g_ua_mon_h, 1000);
+       ret = ua_monitor_set_location_period(g_ua_mon_h, 500);
        msg(" - ua_monitor_set_location_period() ret: [0x%X] [%s]",
                ret, uat_get_error_str(ret));