plugin-api: update-control: Refactor to allocate functions memory in api function... 75/322375/2 accepted/tizen/unified/20250410.014246 accepted/tizen/unified/x/20250410.025359
authorSangYoun Kwak <sy.kwak@samsung.com>
Tue, 8 Apr 2025 07:14:32 +0000 (16:14 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Tue, 8 Apr 2025 07:47:59 +0000 (16:47 +0900)
Previously, function structure was created in the backend and the api
function used it. But this method depends the function structure to the
backend, so it can break the abi rule.
To resolve this issue, update-control is refactored to allocate the
function structure and give it to the backend to fill the required
functions.

Change-Id: Icd92dd2dc9342f94bd7d98a3e34519f4fb7b53e8
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
src/plugin-api/update-control/src/syscommon-plugin-update-control.c

index 6fd20f346c2b2b7f09a583f6f61dcf102cf1b0aa..720552d17a212aa145a32d404138699f5dec7d9d 100644 (file)
@@ -21,6 +21,9 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+
+#include <stdlib.h>
+
 #include <libsyscommon/log.h>
 
 #include <system/syscommon-plugin-common.h>
@@ -36,29 +39,50 @@ static syscommon_plugin_backend_update_control_funcs *funcs = NULL;
 EXPORT
 int syscommon_plugin_update_control_get_backend(int *backend_exists)
 {
+       int ret = 0;
+
+       if (!backend_exists) {
+               _E("Invalid parameter: backend_exists is NULL");
+               return SYSCOMMON_UPDATE_CONTROL_ERROR_INVALID_PARAMETER;
+       }
+
        if (funcs)
                goto get_backend_success;
 
-       int ret = syscommon_plugin_common_get_backend(
+       funcs = calloc(1, sizeof(*funcs));
+       if (!funcs) {
+               _E("Failed to allocate memory for funcs");
+               return SYSCOMMON_UPDATE_CONTROL_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = syscommon_plugin_common_get_backend(
                                SYSCOMMON_PLUGIN_MODULE_UPDATE_CONTROL,
                                (void **)&funcs);
 
-       if (ret < 0) {
-               if ((ret == -ENOENT) && backend_exists) {
-                       _I("update-control backend was not found");
-                       *backend_exists = 0;
-                       return SYSCOMMON_UPDATE_CONTROL_ERROR_NONE;
-               }
+       if (ret == -ENOENT) {
+               _I("update-control backend was not found");
+
+               free(funcs);
+               funcs = NULL;
+
+               *backend_exists = 0;
 
+               return SYSCOMMON_UPDATE_CONTROL_ERROR_NONE;
+       }
+
+       if (ret < 0) {
                _E("Failed to get update-control backend: %d", ret);
+
+               free(funcs);
+               funcs = NULL;
+
                return SYSCOMMON_UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
        }
 
        _I("Success to get update-control backend: %d", ret);
 
 get_backend_success:
-       if (backend_exists)
-               *backend_exists = 1;
+       *backend_exists = 1;
 
        return SYSCOMMON_UPDATE_CONTROL_ERROR_NONE;
 }
@@ -76,10 +100,12 @@ int syscommon_plugin_update_control_put_backend(void)
                _E("Failed to put update-control backend: %d", ret);
                return SYSCOMMON_UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
        }
-       funcs = NULL;
 
        _I("Success to put update-control backend: %d", ret);
 
+       free(funcs);
+       funcs = NULL;
+
        return SYSCOMMON_UPDATE_CONTROL_ERROR_NONE;
 }