Returns unique file paths from the maps file 50/232450/1
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 5 May 2020 08:01:23 +0000 (10:01 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 5 May 2020 08:49:54 +0000 (10:49 +0200)
This prevents duplicate entries in the *.so_info file

Change-Id: I49c4d4949d4d0075b056891557fe027d82b017a0

src/crash-manager/so-info.c

index 5dc26ff..d2526d7 100644 (file)
@@ -215,6 +215,19 @@ static char *get_exe_filename(char *line)
        return NULL;
 }
 
+bool list_contains_string(GSList *list, const char *string, const size_t max_len)
+{
+       if (list == NULL || string == NULL)
+               return false;
+
+       for (GSList *iterator = list; iterator; iterator = iterator->next) {
+               if (strncmp((char*)iterator->data, string, max_len) == 0)
+                       return true;
+       }
+
+       return false;
+}
+
 GSList *get_filepaths(char *map_path)
 {
        char *line = NULL;
@@ -242,7 +255,10 @@ GSList *get_filepaths(char *map_path)
 
                        snprintf(file_name, n+1, "%s", exe_filename);
 
-                       file_list = g_slist_append(file_list, file_name);
+                       if (!list_contains_string(file_list, file_name, PATH_MAX))
+                               file_list = g_slist_append(file_list, file_name);
+                       else
+                               free(file_name);
                }
        }