Index: gtk-v2/src/config.c
===================================================================
--- gtk-v2/src/config.c	(revision 6798)
+++ gtk-v2/src/config.c	(working copy)
@@ -398,6 +398,57 @@
     return 1;
 }
 
+
+/* that ifdef should perhaps become something like !HAVE_SCANDIR (?) */
+#ifdef WIN32
+static int scandir(const char *dir, 
+	struct dirent ***namelist,
+	int (*select)(const struct dirent *),
+	int (*compar)(const struct dirent **, const struct dirent**))
+{
+	DIR * dp;
+	int count, i;
+	struct dirent *entry;
+	struct dirent **files;
+
+	dp = opendir(dir);
+	if (dp == NULL)
+		return 0;
+
+	count = 0;
+	while((entry = readdir(dp)) != NULL)
+	{
+		if (select == NULL  ||  select(entry))
+			count++;
+	}
+	rewinddir(dp);
+	files = malloc(count * sizeof(struct dirent**));
+	*namelist = files;
+	i = 0;
+	while((entry = readdir(dp)) != NULL)
+	{
+		if (select == NULL  ||  select(entry))
+		{
+			files[i] = malloc(sizeof(struct dirent));
+			memcpy(files[i], entry, sizeof(struct dirent));
+			i++;
+		}
+	}
+
+	if (compar != NULL)
+		qsort(files, count, sizeof(struct dirent**), (int (*)(const void*, const void *))compar);
+	closedir(dp);
+	return count;
+}
+
+static int alphasort (const struct dirent **a, const struct dirent **b)
+{
+	return strcmp((*a)->d_name, (*b)->d_name);
+}
+
+#endif
+
+
 /*
  * setup_config_window sets the buttons, combos, etc, to the
  * state that matches the want_config[] values.
@@ -550,6 +601,7 @@
 
 	snprintf(path, MAX_BUF, "%s/themes", CF_DATADIR);
 
+	files = NULL;
 	count = scandir(path, &files, scandir_filter, alphasort);
 
 	for (i=0; i<count; i++) {
@@ -565,7 +617,11 @@
 
 	    gtk_combo_box_append_text(GTK_COMBO_BOX(config_combobox_theme),
 		files[i]->d_name);
+		free(files[i]);
 	}
+	if (files != NULL)
+		free(files);
+
 	/* Just to set this for below */
 	count =  gtk_tree_model_iter_n_children(model, NULL);
     }
