gio-tool: Do not leak GOptionContext

GOptionContext is freed only in case of success. Free the context
also in case of failure.

https://bugzilla.gnome.org/show_bug.cgi?id=776169
This commit is contained in:
Ondrej Holy
2016-12-19 12:11:13 +01:00
parent 292f10d053
commit fb7d2184a6
16 changed files with 52 additions and 0 deletions

View File

@@ -136,6 +136,7 @@ handle_cat (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -143,12 +144,14 @@ handle_cat (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc < 2)
{
show_help (context, _("No locations given"));
g_option_context_free (context);
return 1;
}

View File

@@ -110,6 +110,7 @@ handle_copy (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -117,12 +118,14 @@ handle_copy (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc < 3)
{
show_help (context, NULL);
g_option_context_free (context);
return 1;
}
@@ -132,6 +135,7 @@ handle_copy (int argc, char *argv[], gboolean do_help)
{
show_help (context, NULL);
g_object_unref (dest);
g_option_context_free (context);
return 1;
}
@@ -144,6 +148,7 @@ handle_copy (int argc, char *argv[], gboolean do_help)
show_help (context, message);
g_free (message);
g_object_unref (dest);
g_option_context_free (context);
return 1;
}

View File

@@ -296,6 +296,7 @@ handle_info (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -303,12 +304,14 @@ handle_info (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc < 2)
{
show_help (context, _("No locations given"));
g_option_context_free (context);
return 1;
}

View File

@@ -178,6 +178,7 @@ handle_list (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -185,6 +186,7 @@ handle_list (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}

View File

@@ -83,6 +83,7 @@ handle_mime (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -90,12 +91,14 @@ handle_mime (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc != 2 && argc != 3)
{
show_help (context, _("Must specify a single mimetype, and maybe a handler"));
g_option_context_free (context);
return 1;
}

View File

@@ -59,6 +59,7 @@ handle_mkdir (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -66,12 +67,14 @@ handle_mkdir (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc < 2)
{
show_help (context, _("No locations given"));
g_option_context_free (context);
return 1;
}

View File

@@ -211,6 +211,7 @@ handle_monitor (int argc, gchar *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -218,12 +219,14 @@ handle_monitor (int argc, gchar *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (!watch_dirs || !watch_files || !watch_direct || !watch_silent || !watch_default)
{
show_help (context, _("No locations given"));
g_option_context_free (context);
return 1;
}

View File

@@ -1148,6 +1148,7 @@ handle_mount (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -1155,6 +1156,7 @@ handle_mount (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}

View File

@@ -113,12 +113,14 @@ handle_move (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc < 3)
{
show_help (context, NULL);
g_option_context_free (context);
return 1;
}
@@ -128,6 +130,7 @@ handle_move (int argc, char *argv[], gboolean do_help)
{
show_help (context, NULL);
g_object_unref (dest);
g_option_context_free (context);
return 1;
}
@@ -140,6 +143,7 @@ handle_move (int argc, char *argv[], gboolean do_help)
show_help (context, message);
g_free (message);
g_object_unref (dest);
g_option_context_free (context);
return 1;
}

View File

@@ -54,6 +54,7 @@ handle_open (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -61,12 +62,14 @@ handle_open (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc < 2)
{
show_help (context, _("No locations given"));
g_option_context_free (context);
return 1;
}

View File

@@ -55,6 +55,7 @@ handle_remove (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -62,12 +63,14 @@ handle_remove (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc == 1)
{
show_help (context, _("No locations given"));
g_option_context_free (context);
return 1;
}

View File

@@ -53,6 +53,7 @@ handle_rename (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -60,17 +61,20 @@ handle_rename (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc < 3)
{
show_help (context, _("Missing argument"));
g_option_context_free (context);
return 1;
}
if (argc > 3)
{
show_help (context, _("Too many arguments"));
g_option_context_free (context);
return 1;
}

View File

@@ -171,6 +171,7 @@ handle_save (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -178,18 +179,21 @@ handle_save (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc < 2)
{
show_help (context, _("No destination given"));
g_option_context_free (context);
return 1;
}
if (argc > 2)
{
show_help (context, _("Too many arguments"));
g_option_context_free (context);
return 1;
}

View File

@@ -96,6 +96,7 @@ handle_set (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -103,18 +104,21 @@ handle_set (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
if (argc < 2)
{
show_help (context, _("Location not specified"));
g_option_context_free (context);
return 1;
}
if (argc < 3)
{
show_help (context, _("Attribute not specified"));
g_option_context_free (context);
return 1;
}
@@ -124,12 +128,14 @@ handle_set (int argc, char *argv[], gboolean do_help)
if ((argc < 4) && (type != G_FILE_ATTRIBUTE_TYPE_INVALID))
{
show_help (context, _("Value not specified"));
g_option_context_free (context);
return 1;
}
if ((argc > 4) && (type != G_FILE_ATTRIBUTE_TYPE_STRINGV))
{
show_help (context, _("Too many arguments"));
g_option_context_free (context);
return 1;
}

View File

@@ -89,6 +89,7 @@ handle_trash (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -96,6 +97,7 @@ handle_trash (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}

View File

@@ -247,6 +247,7 @@ handle_tree (int argc, char *argv[], gboolean do_help)
if (do_help)
{
show_help (context, NULL);
g_option_context_free (context);
return 0;
}
@@ -256,6 +257,7 @@ handle_tree (int argc, char *argv[], gboolean do_help)
{
show_help (context, error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}