diff options
author | Behdad Esfahbod <behdad@src.gnome.org> | 2005-07-26 11:08:08 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2005-07-26 11:08:08 +0000 |
commit | 8cefdbcfb000191a8d8a506576b1d94d98f6f00d (patch) | |
tree | 5b4dac8afbb869e62e47bb35182ffe729b1d35ca | |
parent | 6a100fc4973fc1e5c044fb8dc1c55be430cbd707 (diff) | |
download | pango-8cefdbcfb000191a8d8a506576b1d94d98f6f00d.tar.gz |
Fixed a couple of leaks and freed memory after use.
-rw-r--r-- | examples/cairoview.c | 6 | ||||
-rw-r--r-- | examples/pangoft2topgm.c | 32 | ||||
-rw-r--r-- | examples/renderdemo.c | 8 | ||||
-rw-r--r-- | examples/renderdemo.h | 1 |
4 files changed, 35 insertions, 12 deletions
diff --git a/examples/cairoview.c b/examples/cairoview.c index 7b4ad1d7..82a57b5e 100644 --- a/examples/cairoview.c +++ b/examples/cairoview.c @@ -295,6 +295,10 @@ int main (int argc, char **argv) } } - done: +done: + + g_object_unref (context); + finalize (); + return 0; } diff --git a/examples/pangoft2topgm.c b/examples/pangoft2topgm.c index c3f90090..46549947 100644 --- a/examples/pangoft2topgm.c +++ b/examples/pangoft2topgm.c @@ -30,8 +30,6 @@ #include <pango/pangoft2.h> -static char *tmpfile_name; - static void ft2_render (PangoLayout *layout, int x, @@ -49,6 +47,8 @@ main(int argc, char *argv[]) PangoFontMap *fontmap; GError *error = NULL; gboolean do_convert = FALSE; + int exit_status = 0; + char *tmpfile_name; g_type_init(); @@ -86,6 +86,8 @@ main(int argc, char *argv[]) pango_ft2_font_map_set_default_substitute (PANGO_FT2_FONT_MAP (fontmap), fc_substitute_func, NULL, NULL); context = pango_ft2_font_map_create_context (PANGO_FT2_FONT_MAP (fontmap)); + g_object_unref (fontmap); + /* Write contents as pgm file */ { FT_Bitmap bitmap; @@ -130,8 +132,6 @@ main(int argc, char *argv[]) /* Convert to a different format, if necessary */ if (do_convert) { - int exit_status; - gchar *command = g_strdup_printf ("convert %s %s", tmpfile_name, opt_output); @@ -139,19 +139,21 @@ main(int argc, char *argv[]) fail ("When running ImageMagick 'convert' command: %s\n", error->message); + g_free (command); + if (tmpfile_name) { remove (tmpfile_name); + g_free (tmpfile_name); tmpfile_name = NULL; } - + if (exit_status) - exit (1); + goto done; } if (opt_display) { - int exit_status; gchar *title = get_options_string (); gchar *title_quoted = g_shell_quote (title); @@ -167,12 +169,20 @@ main(int argc, char *argv[]) g_free (title_quoted); if (tmpfile_name) - remove (tmpfile_name); - + { + remove (tmpfile_name); + g_free (tmpfile_name); + tmpfile_name = NULL; + } + if (exit_status) - exit (1); + goto done; } } - return 0; +done: + g_object_unref (context); + finalize (); + + return exit_status ? 1 : 0; } diff --git a/examples/renderdemo.c b/examples/renderdemo.c index 34d9a057..de324d79 100644 --- a/examples/renderdemo.c +++ b/examples/renderdemo.c @@ -426,6 +426,8 @@ parse_options (int argc, char *argv[]) if (!arg_context_parse (arg_context, &argc, &argv, &error)) fail ("%s", error->message); + + arg_context_free (arg_context); if ((opt_text && argc != 1) || (!opt_text && argc != 2)) @@ -475,3 +477,9 @@ parse_options (int argc, char *argv[]) !pango_parse_markup (text, -1, 0, NULL, NULL, NULL, &error)) fail ("Cannot parse input as markup: %s", error->message); } + +void +finalize (void) +{ + g_free (text); +} diff --git a/examples/renderdemo.h b/examples/renderdemo.h index 84fc56b0..81fed921 100644 --- a/examples/renderdemo.h +++ b/examples/renderdemo.h @@ -47,6 +47,7 @@ void do_output (PangoContext *context, gpointer cb_data, int *width, int *height); +void finalize (void); void fc_substitute_func (FcPattern *pattern, gpointer data); gchar *get_options_string (void); |