pass: Put resource properly to prevent memory leak 10/138110/3
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 11 Jul 2017 05:54:57 +0000 (14:54 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Wed, 12 Jul 2017 01:13:44 +0000 (10:13 +0900)
There are two cases which can cause memory leak during pass init/exit:
 1. When resource initialization is failed, it just skips that
    resource without putting it.
 2. In the case of failure while freeing resources, it is also skipped
    putting that resource.

To prevent memory leak, the resource will be put on both cases.

Change-Id: I4008b7785e0dbbc318b38eb573bf739e0a848b6c
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
src/pass/pass.c

index 8cf368f..dfea1d0 100644 (file)
@@ -251,6 +251,11 @@ static int pass_init_done(void *data, void *user_data)
                if (ret < 0) {
                        _E("Cannot initialize the pass '%s' resource (%d)\n",
                                        cdata->res_name, ret);
+
+                       ret = pass_put_resource(pass_res);
+                       if (ret < 0)
+                               _E("Cannot put the pass '%s' resource (%d)\n",
+                                       cdata->res_name, ret);
                        continue;
                }
        }
@@ -267,11 +272,9 @@ static int pass_exit_done(void)
                struct pass_conf_data *cdata = &g_pass.res[i].cdata;
 
                ret = pass_resource_exit(pass_res);
-               if (ret < 0) {
+               if (ret < 0)
                        _E("Cannot exit the pass '%s' resource (%d)\n",
                                        cdata->res_name, ret);
-                       continue;
-               }
 
                ret = pass_put_resource(pass_res);
                if (ret < 0) {