ges: Plug leaks in new ges-launch and related

This commit is contained in:
Thibault Saunier 2020-02-20 17:13:46 -03:00
parent 056ac5eeb0
commit 4e4473ef8f
7 changed files with 58 additions and 29 deletions

View file

@ -877,6 +877,7 @@ ges_project_create_asset_sync (GESProject * project, const gchar * id,
return NULL; return NULL;
} }
g_free (internal_id);
/* TODO Add a GCancellable somewhere in our API */ /* TODO Add a GCancellable somewhere in our API */
while (retry) { while (retry) {

View file

@ -698,6 +698,7 @@ _set_control_source (GstValidateScenario * scenario, GstValidateAction * action)
source, property_name, binding_type); source, property_name, binding_type);
done: done:
g_free (property_name);
g_free (element_name); g_free (element_name);
g_free (binding_type); g_free (binding_type);
g_free (source_type); g_free (source_type);

View file

@ -726,15 +726,15 @@ ges_launcher_get_playback_option_group (GESLauncherParsedOptions * opts)
} }
gboolean gboolean
ges_launcher_parse_options (GESLauncherParsedOptions * opts, gchar ** arguments, ges_launcher_parse_options (GESLauncherParsedOptions * opts,
gint * argc, GOptionContext * ctx, GError ** error) gchar ** arguments[], gint * argc, GOptionContext * ctx, GError ** error)
{ {
gboolean res; gboolean res;
gchar **argv;
GOptionGroup *main_group; GOptionGroup *main_group;
gint nargs = 0, tmpargc; gint nargs = 0, tmpargc;
gchar **commands = NULL, *help, *tmp; gchar **commands = NULL, *help, *tmp;
GError *err = NULL; GError *err = NULL;
gboolean owns_ctx = ctx == NULL;
GOptionEntry options[] = { GOptionEntry options[] = {
{"disable-mixing", 0, 0, G_OPTION_ARG_NONE, &opts->disable_mixing, {"disable-mixing", 0, 0, G_OPTION_ARG_NONE, &opts->disable_mixing,
"Do not use mixing elements to mix layers together.", NULL} "Do not use mixing elements to mix layers together.", NULL}
@ -786,12 +786,11 @@ ges_launcher_parse_options (GESLauncherParsedOptions * opts, gchar ** arguments,
if (!ctx) if (!ctx)
ctx = g_option_context_new ("- plays or renders a timeline."); ctx = g_option_context_new ("- plays or renders a timeline.");
argv = arguments; tmpargc = argc ? *argc : g_strv_length (*arguments);
tmpargc = g_strv_length (argv);
if (tmpargc > 2) { if (tmpargc > 2) {
nargs = tmpargc - 2; nargs = tmpargc - 2;
commands = &argv[2]; commands = &(*arguments)[2];
} }
tmp = ges_command_line_formatter_get_help (nargs, commands); tmp = ges_command_line_formatter_get_help (nargs, commands);
@ -818,13 +817,17 @@ ges_launcher_parse_options (GESLauncherParsedOptions * opts, gchar ** arguments,
g_option_context_add_group (ctx, ges_launcher_get_info_option_group (opts)); g_option_context_add_group (ctx, ges_launcher_get_info_option_group (opts));
g_option_context_set_ignore_unknown_options (ctx, TRUE); g_option_context_set_ignore_unknown_options (ctx, TRUE);
res = g_option_context_parse (ctx, &tmpargc, &argv, &err); res = g_option_context_parse_strv (ctx, arguments, &err);
if (argc) if (argc)
*argc = tmpargc; *argc = tmpargc;
if (err) if (err)
g_propagate_error (error, err); g_propagate_error (error, err);
if (owns_ctx) {
g_option_context_free (ctx);
}
return res; return res;
} }
@ -832,7 +835,7 @@ static gboolean
_local_command_line (GApplication * application, gchar ** arguments[], _local_command_line (GApplication * application, gchar ** arguments[],
gint * exit_status) gint * exit_status)
{ {
gchar **argv; gboolean res = TRUE;
gint argc; gint argc;
GError *error = NULL; GError *error = NULL;
GESLauncher *self = GES_LAUNCHER (application); GESLauncher *self = GES_LAUNCHER (application);
@ -840,22 +843,22 @@ _local_command_line (GApplication * application, gchar ** arguments[],
GOptionContext *ctx = g_option_context_new ("- plays or renders a timeline."); GOptionContext *ctx = g_option_context_new ("- plays or renders a timeline.");
*exit_status = 0; *exit_status = 0;
argv = *arguments; argc = g_strv_length (*arguments);
argc = g_strv_length (argv);
gst_init (&argc, &argv); gst_init (&argc, arguments);
if (!ges_launcher_parse_options (opts, *arguments, &argc, ctx, &error)) { if (!ges_launcher_parse_options (opts, arguments, &argc, ctx, &error)) {
gst_init (NULL, NULL); gst_init (NULL, NULL);
printerr ("Error initializing: %s\n", error->message); printerr ("Error initializing: %s\n", error->message);
g_option_context_free (ctx); g_option_context_free (ctx);
g_error_free (error); g_error_free (error);
*exit_status = 1; *exit_status = 1;
return TRUE; goto done;
} }
if (opts->inspect_action_type) { if (opts->inspect_action_type) {
ges_validate_print_action_types ((const gchar **) argv + 1, argc - 1); ges_validate_print_action_types ((const gchar **) &((*arguments)[1]),
return TRUE; argc - 1);
goto done;
} }
if (!opts->load_path && !opts->scenario && !opts->list_transitions if (!opts->load_path && !opts->scenario && !opts->list_transitions
@ -863,20 +866,21 @@ _local_command_line (GApplication * application, gchar ** arguments[],
g_printf ("%s", g_option_context_get_help (ctx, TRUE, NULL)); g_printf ("%s", g_option_context_get_help (ctx, TRUE, NULL));
g_option_context_free (ctx); g_option_context_free (ctx);
*exit_status = 1; *exit_status = 1;
return TRUE; goto done;
} }
g_option_context_free (ctx); g_option_context_free (ctx);
opts->sanitized_timeline = sanitize_timeline_description (argc, argv); opts->sanitized_timeline = sanitize_timeline_description (*arguments);
if (!g_application_register (application, NULL, &error)) { if (!g_application_register (application, NULL, &error)) {
*exit_status = 1; *exit_status = 1;
g_clear_error (&error); g_clear_error (&error);
return FALSE; res = FALSE;
} }
return TRUE; done:
return res;
} }
static void static void
@ -953,12 +957,35 @@ _shutdown (GApplication * application)
G_APPLICATION_CLASS (ges_launcher_parent_class)->shutdown (application); G_APPLICATION_CLASS (ges_launcher_parent_class)->shutdown (application);
} }
static void
_finalize (GObject * object)
{
GESLauncher *self = GES_LAUNCHER (object);
GESLauncherParsedOptions *opts = &self->priv->parsed_options;
g_free (opts->load_path);
g_free (opts->save_path);
g_free (opts->save_only_path);
g_free (opts->outputuri);
g_free (opts->format);
g_free (opts->encoding_profile);
g_free (opts->videosink);
g_free (opts->audiosink);
g_free (opts->video_track_caps);
g_free (opts->audio_track_caps);
g_free (opts->scenario);
G_OBJECT_CLASS (ges_launcher_parent_class)->finalize (object);
}
static void static void
ges_launcher_class_init (GESLauncherClass * klass) ges_launcher_class_init (GESLauncherClass * klass)
{ {
G_APPLICATION_CLASS (klass)->local_command_line = _local_command_line; G_APPLICATION_CLASS (klass)->local_command_line = _local_command_line;
G_APPLICATION_CLASS (klass)->startup = _startup; G_APPLICATION_CLASS (klass)->startup = _startup;
G_APPLICATION_CLASS (klass)->shutdown = _shutdown; G_APPLICATION_CLASS (klass)->shutdown = _shutdown;
G_OBJECT_CLASS (klass)->finalize = _finalize;
} }
static void static void

View file

@ -64,8 +64,8 @@ typedef struct
gboolean list_transitions; gboolean list_transitions;
gboolean inspect_action_type; gboolean inspect_action_type;
gchar *sanitized_timeline; gchar *sanitized_timeline;
const gchar *video_track_caps; gchar *video_track_caps;
const gchar *audio_track_caps; gchar *audio_track_caps;
gboolean embed_nesteds; gboolean embed_nesteds;
} GESLauncherParsedOptions; } GESLauncherParsedOptions;
@ -91,7 +91,7 @@ GType ges_launcher_get_type (void);
GESLauncher* ges_launcher_new (void); GESLauncher* ges_launcher_new (void);
gint ges_launcher_get_exit_status (GESLauncher *self); gint ges_launcher_get_exit_status (GESLauncher *self);
gboolean ges_launcher_parse_options(GESLauncherParsedOptions* opts, gchar** arguments, gint *argc, GOptionContext* ctx, GError** error); gboolean ges_launcher_parse_options(GESLauncherParsedOptions* opts, gchar*** arguments, gint *argc, GOptionContext* ctx, GError** error);
G_END_DECLS G_END_DECLS

View file

@ -140,11 +140,11 @@ ges_validate_activate (GstPipeline * pipeline, GESLauncherParsedOptions * opts)
ges_options_full[0] = g_strdup ("something"); ges_options_full[0] = g_strdup ("something");
for (i = 0; ges_options[i]; i++) for (i = 0; ges_options[i]; i++)
ges_options_full[i + 1] = ges_options[i]; ges_options_full[i + 1] = g_strdup (ges_options[i]);
ges_launcher_parse_options (opts, ges_options_full, NULL, NULL, NULL); ges_launcher_parse_options (opts, &ges_options_full, NULL, NULL, NULL);
g_free (ges_options);
g_strfreev (ges_options_full); g_strfreev (ges_options_full);
g_strfreev (ges_options);
} }
} }
} }

View file

@ -64,15 +64,15 @@ _sanitize_argument (gchar * arg)
} }
gchar * gchar *
sanitize_timeline_description (int argc, char **argv) sanitize_timeline_description (gchar ** args)
{ {
gint i; gint i;
gchar *string = g_strdup (" "); gchar *string = g_strdup (" ");
for (i = 1; i < argc; i++) { for (i = 1; args[i]; i++) {
gchar *new_string; gchar *new_string;
gchar *sanitized = _sanitize_argument (argv[i]); gchar *sanitized = _sanitize_argument (args[i]);
new_string = g_strconcat (string, " ", sanitized, NULL); new_string = g_strconcat (string, " ", sanitized, NULL);

View file

@ -20,7 +20,7 @@
#include <gst/pbutils/pbutils.h> #include <gst/pbutils/pbutils.h>
#include <gst/pbutils/encoding-profile.h> #include <gst/pbutils/encoding-profile.h>
gchar * sanitize_timeline_description (int argc, char **argv); gchar * sanitize_timeline_description (gchar **args);
gboolean get_flags_from_string (GType type, const gchar * str_flags, guint *val); gboolean get_flags_from_string (GType type, const gchar * str_flags, guint *val);
gchar * ensure_uri (const gchar * location); gchar * ensure_uri (const gchar * location);
GstEncodingProfile * parse_encoding_profile (const gchar * format); GstEncodingProfile * parse_encoding_profile (const gchar * format);