Properly build path names for obt_paths_try_exec
[dana/openbox.git] / obt / paths.c
index e2e4859..25cb6b0 100644 (file)
@@ -88,8 +88,10 @@ static GSList* split_paths(const gchar *paths)
     if (!paths)
         return NULL;
     spl = g_strsplit(paths, ":", -1);
-    for (it = spl; *it; ++it)
-        list = slist_path_add(list, *it, (GSListFunc) g_slist_append);
+    for (it = spl; *it; ++it) {
+        if ((*it)[0]) /* skip empty strings */
+            list = slist_path_add(list, *it, (GSListFunc) g_slist_append);
+    }
     g_free(spl);
     return list;
 }
@@ -126,7 +128,7 @@ static void find_uid_gid(uid_t *u, gid_t **g, guint *n)
     }
     endgrent();
 
-    qsort(*g, sizeof(gid_t), *n, gid_cmp);
+    qsort(*g, *n, sizeof(gid_t), gid_cmp);
 }
 
 ObtPaths* obt_paths_new(void)
@@ -231,9 +233,13 @@ void obt_paths_unref(ObtPaths *p)
         for (it = p->autostart_dirs; it; it = g_slist_next(it))
             g_free(it->data);
         g_slist_free(p->autostart_dirs);
+        for (it = p->exec_dirs; it; it = g_slist_next(it))
+            g_free(it->data);
+        g_slist_free(p->exec_dirs);
         g_free(p->config_home);
         g_free(p->data_home);
         g_free(p->cache_home);
+        g_free(p->gid);
 
         g_slice_free(ObtPaths, p);
     }
@@ -329,9 +335,10 @@ static inline gboolean try_exec(const ObtPaths *const p,
                                 const gchar *const path)
 {
     struct stat st;
-    BSEARCH_SETUP(guint);
+    BSEARCH_SETUP();
 
-    stat(path, &st);
+    if (stat(path, &st) != 0)
+        return FALSE;
 
     if (!S_ISREG(st.st_mode))
         return FALSE;
@@ -352,7 +359,7 @@ gboolean obt_paths_try_exec(ObtPaths *p, const gchar *path)
         GSList *it;
 
         for (it = p->exec_dirs; it; it = g_slist_next(it)) {
-            gchar *f = g_strdup_printf(it->data, G_DIR_SEPARATOR_S, path);
+            gchar *f = g_build_filename(it->data, path, NULL);
             gboolean e = try_exec(p, f);
             g_free(f);
             if (e) return TRUE;