Add try-catch for sensord_disconnect function 33/311033/1 accepted/tizen/unified/20240516.163519
authorSangYoun Kwak <sy.kwak@samsung.com>
Mon, 13 May 2024 06:49:28 +0000 (15:49 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Mon, 13 May 2024 07:33:27 +0000 (16:33 +0900)
The capi function 'sensor_destroy_listener' can throw
std::invalid_argument but this function can be used in C(which cannot
handle thrown exceptions) so a try-catch statement is added to handle
this exception.

This patch will solve the SVACE report with WGID 203810.

Change-Id: I5eda70a6afb62f63c823df6f96c73271872def4d
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
src/sensor.cpp

index 9473be7..0225b18 100644 (file)
@@ -446,7 +446,13 @@ int sensor_destroy_listener(sensor_listener_h listener)
        if (listener->magic != SENSOR_LISTENER_MAGIC)
                return SENSOR_ERROR_INVALID_PARAMETER;
 
-       sensord_disconnect(listener->id);
+       try {
+               sensord_disconnect(listener->id);
+       } catch (std::invalid_argument &e) {
+               _E("sensord_disconnect failed: %s", e.what());
+               return SENSOR_ERROR_INVALID_PARAMETER;
+       }
+
        listener->magic = 0;
 
        delete (sensor_listener_s *)listener;