Permalink
Browse files

Improve docs, fix memory leak, don't segfault on Linux when grubenv i…

…s missing
  • Loading branch information...
1 parent 6fe7918 commit 9ea522f12317ffcea24cd3d978fb6c307671fd52 David Mohr committed May 17, 2010
Showing with 36 additions and 7 deletions.
  1. +9 −1 src/gchd-unix.c
  2. +19 −6 src/gchd.c
  3. +8 −0 src/grub-choose-default-util.c
View
@@ -79,7 +79,7 @@ get_default_entry (Gchd * gchd, GError **error)
{
/* an error occurred which is passed onto the caller through
* the error argument */
- return "";
+ return NULL;
}
lines = g_strsplit (s_output, "\n", -1);
@@ -96,6 +96,14 @@ get_default_entry (Gchd * gchd, GError **error)
}
}
+ if (default_entry == NULL)
+ {
+ /* The output was not parseable, just assume no default is set.
+ * This happens when grubenv does not yet exist (is not initialized).
+ * FIXME: could there be other reasons that we need to treat differently? */
+ default_entry = "";
+ }
+
return default_entry;
}
View
@@ -124,7 +124,8 @@ gchd_get_menu_entries (Gchd *gchd, GList **entries, GError **error)
*
* Searches in predetermined subdirectories for @file.
*
- * Returns: the full path to the @file as a string to be freed by the caller.
+ * Returns: the full path to the @file as a string to be freed by the caller, or
+ * %NULL if no file was found, and error is set accordingly.
**/
gchar *
gchd_get_grub_file_from_root (Gchd * gchd, const gchar * root, const gchar * file, GError **error)
@@ -177,7 +178,8 @@ gchd_get_grub_file_from_root (Gchd * gchd, const gchar * root, const gchar * fil
* but on Windows it searches on all possible volumes.
*
* Returns: a string containing the full path to the file, which needs
- * to be freed by the caller.
+ * to be freed by the caller, or
+ * %NULL on error.
**/
gchar *
gchd_get_grub_file (Gchd * gchd, const gchar * file, GError **error)
@@ -207,9 +209,6 @@ gchd_get_grub_file (Gchd * gchd, const gchar * file, GError **error)
mounts = g_list_reverse (mounts);
cfg = NULL;
- g_set_error (error, GCHD_ERROR,
- GCHD_ERROR_NO_VOLUMES,
- "No volumes were found in the system");
for (iter = mounts; iter != NULL && cfg == NULL; iter = g_list_next (iter))
{
@@ -219,12 +218,15 @@ gchd_get_grub_file (Gchd * gchd, const gchar * file, GError **error)
f_root = g_mount_get_root (mnt);
root = g_file_get_path (f_root);
- DBG ("Considering root %s", root);
if (strcmp (root, "A:\\") != 0)
{
DBG ("Using root %s", root);
+ /* There could be a left-over error from the past iteration.
+ * Note that we free it in the beginning, because the last error
+ * needs to be kept to pass on to the caller.
+ */
if (error && *error)
{
g_error_free (*error);
@@ -246,9 +248,20 @@ gchd_get_grub_file (Gchd * gchd, const gchar * file, GError **error)
g_list_free (mounts);
g_object_unref (volmon);
#else
+ /* FIXME: is it fair to assume that on Unix the file will always be
+ * in /boot/grub ?
+ */
cfg = gchd_get_grub_file_from_root (gchd, "/", file, error);
#endif
+ if (cfg == NULL)
+ {
+ /* We never found the directory */
+ g_set_error (error, GCHD_ERROR,
+ GCHD_ERROR_NO_VOLUMES,
+ "No volumes were found in the system");
+ }
+
return cfg;
}
@@ -18,6 +18,14 @@
#include "grub-choose-default-util.h"
+/**
+ * grub_choose_default_error:
+ * #parent : a parent window, or NULL
+ * #error : an error to display
+ *
+ * Displays the message of #error. A modal dialog is used if the optional
+ * parameter #parent is non-%NULL.
+ **/
void
grub_choose_default_error (GtkWidget *parent, GError *error)
{

0 comments on commit 9ea522f

Please sign in to comment.