Przeglądaj źródła

d.mon: fix segfault when no MONITOR dir exists

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@64411 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 10 lat temu
rodzic
commit
406db2944a
1 zmienionych plików z 8 dodań i 5 usunięć
  1. 8 5
      display/d.mon/list.c

+ 8 - 5
display/d.mon/list.c

@@ -37,11 +37,16 @@ void list_mon(char ***list, int *n)
     struct dirent *dp;
     DIR *dirp;
 
-    mon_path = get_path(NULL, TRUE);
-    dirp = opendir(mon_path);
-
     *list = NULL;
     *n    = 0;
+    
+    mon_path = get_path(NULL, TRUE);
+    dirp = opendir(mon_path);
+    G_free(mon_path);
+    
+    if (!dirp)
+        return;
+    
     while ((dp = readdir(dirp)) != NULL) {
         *list = G_realloc(*list, (*n + 1) * sizeof(char *));
         if (!dp->d_name || dp->d_name[0] == '.')
@@ -50,8 +55,6 @@ void list_mon(char ***list, int *n)
         (*n)++;
     }
     closedir(dirp);
-    
-    G_free(mon_path);
 }
 
 /* print list of running monitors */