mmi: add NULL checks and free allocated variables to prevent RESOURCE_LEAK 02/264102/1
authorDuna Oh <duna.oh@samsung.com>
Fri, 10 Sep 2021 07:58:36 +0000 (16:58 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Mon, 13 Sep 2021 11:27:03 +0000 (20:27 +0900)
Change-Id: I4795673e189f75c8b294aa85b17352a244ad4da5

src/mmi-fusion.c
src/mmi-provider.c

index a0687e9..7752cc8 100644 (file)
@@ -42,6 +42,12 @@ _fusion_load_module(const char *fusion_name)
 {
        mmi_fusion_handle *fusion = (mmi_fusion_handle *)calloc(1, sizeof(mmi_fusion_handle));
 
+       if (!fusion)
+       {
+               LOGE("Failed to alloc fusion handle");
+               return 0;
+       }
+
        void *fusion_info = NULL;
        mmi_fusion_module *mmi_fusion_module_info = NULL;
 
@@ -50,7 +56,7 @@ _fusion_load_module(const char *fusion_name)
        if(!fusion_info)
        {
                LOGE("Failed to dlopen(error :%s, path :%s)!\n", dlerror(), fusion_name);
-               return 0;
+               goto err;
        }
 
        mmi_fusion_module_info = dlsym(fusion_info, "mmi_fusion_module_info");
@@ -92,6 +98,9 @@ _fusion_load_module(const char *fusion_name)
 err:
        if(fusion_info)
                dlclose(fusion_info);
+
+       if(fusion)
+               free(fusion);
        return 0;
 }
 
@@ -121,6 +130,8 @@ _modality_fusions_lookup(void)
                }
        }
 
+       closedir(dir);
+
        return cnt;
 }
 
index 6e39132..3dc9a74 100644 (file)
@@ -142,6 +142,12 @@ _provider_load_module(const char *provider_name)
 {
        mmi_provider_handle *provider = (mmi_provider_handle *)calloc(1, sizeof(mmi_provider_handle));
 
+       if (!provider)
+       {
+               LOGE("Failed to alloc provider handle");
+               return;
+       }
+
        void *provider_info = NULL;
        mmi_provider_module *mmi_provider_module_info = NULL;
        mmi_provider_module_data *provider_module_data = NULL;
@@ -151,7 +157,7 @@ _provider_load_module(const char *provider_name)
        if(!provider_info)
        {
                LOGE("Failed to dlopen(error :%s, path :%s)!\n", dlerror(), provider_name);
-               return;
+               goto err;
        }
 
        mmi_provider_module_info = dlsym(provider_info, "mmi_provider_module_info");
@@ -192,6 +198,9 @@ err:
 
        if(provider_info)
                dlclose(provider_info);
+
+       if(provider)
+               free(provider);
        return;
 }