plugin-api: sessiond: Refactor to allocate functions memory in api function for ABI 14/322614/1 accepted/tizen/9.0/unified/20250415.165856
authorMichal Bloch <m.bloch@samsung.com>
Tue, 8 Apr 2025 17:42:58 +0000 (19:42 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Fri, 11 Apr 2025 10:25:35 +0000 (12:25 +0200)
Resolves ABI compatibility, similar to earlier changes in update-control.

Change-Id: Ied4a4e9f5003d397dbc8a138407665e023ea3af9

src/plugin-api/sessiond/src/syscommon-plugin-sessiond.c

index 04f2c19f667328b69fac7c9c94b855775da10783..09f86dd5c50d8ead048d2c9367328114af3afaa0 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,32 +39,48 @@ static syscommon_plugin_backend_sessiond_funcs *funcs = NULL;
 EXPORT
 int syscommon_plugin_sessiond_get_backend(int *backend_exists)
 {
+       int ret = 0;
+       if (!backend_exists) {
+               _E("Invalid parameter: backend_exists is NULL");
+               return -EINVAL;
+       }
+
        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 -ENOMEM;
+       }
+
+       ret = syscommon_plugin_common_get_backend(
                                SYSCOMMON_PLUGIN_MODULE_SESSIOND,
                                (void **)&funcs);
 
-       if (ret < 0) {
-               if (ret == -ENOENT) {
-                       _I("sessiond backend was not found");
-                       if (backend_exists)
-                               *backend_exists = 0;
-                       return 0;
-               }
-
-               _E("Failed to get sessiond backend: %d", ret);
-               return ret;
+       if (ret == -ENOENT) {
+               _I("sessiond plugin backend was not found");
+               ret = 0;
+               goto get_backend_failure;
+       } else if (ret < 0) {
+               _E("Failed to get sessiond plugin backend: %d", ret);
+               goto get_backend_failure;
        }
 
        _I("Success to get sessiond backend: %d", ret);
 
 get_backend_success:
-       if (backend_exists)
-               *backend_exists = 1;
+       *backend_exists = 1;
 
        return 0;
+
+get_backend_failure:
+       free(funcs);
+       funcs = NULL;
+
+       *backend_exists = 0;
+
+       return ret;
 }
 
 EXPORT
@@ -77,10 +96,12 @@ int syscommon_plugin_sessiond_put_backend(void)
                _E("Failed to put sessiond backend: %d", ret);
                return ret;
        }
-       funcs = NULL;
 
        _I("Success to put sessiond backend: %d", ret);
 
+       free(funcs);
+       funcs = NULL;
+
        return 0;
 }