[Goodies-commits] r6453 - in xfce4-screenshooter/trunk: . lib
Jerome Guelfucci
jeromeg at xfce.org
Tue Jan 13 23:03:50 CET 2009
Author: jeromeg
Date: 2009-01-13 22:03:49 +0000 (Tue, 13 Jan 2009)
New Revision: 6453
Modified:
xfce4-screenshooter/trunk/ChangeLog
xfce4-screenshooter/trunk/lib/screenshooter-actions.c
xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c
xfce4-screenshooter/trunk/lib/screenshooter-utils.c
Log:
Thanks to Jannis and Stephan for the C lesson !
* lib/screenshooter-dialogs.c: (generate_filename_for_uri) rewritten
to avoid a memory leak on each step of the loop.
* lib/screenshooter-actions.c: remove two memory leaks.
Modified: xfce4-screenshooter/trunk/ChangeLog
===================================================================
--- xfce4-screenshooter/trunk/ChangeLog 2009-01-13 20:10:59 UTC (rev 6452)
+++ xfce4-screenshooter/trunk/ChangeLog 2009-01-13 22:03:49 UTC (rev 6453)
@@ -1,3 +1,11 @@
+2009-01-13 jeromeg
+
+ Thanks to Jannis and Stephan for the C lesson !
+
+ * lib/screenshooter-dialogs.c: (generate_filename_for_uri) rewritten
+ to avoid a memory leak on each step of the loop.
+ * lib/screenshooter-actions.c: remove two memory leaks.
+
2009-01-09
* src/xfce4-screenshooter.desktop.in.in,
Modified: xfce4-screenshooter/trunk/lib/screenshooter-actions.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-actions.c 2009-01-13 20:10:59 UTC (rev 6452)
+++ xfce4-screenshooter/trunk/lib/screenshooter-actions.c 2009-01-13 22:03:49 UTC (rev 6453)
@@ -28,9 +28,14 @@
{
if (sd->show_save_dialog == 1)
{
+ gchar *home = g_strdup (DEFAULT_SAVE_DIRECTORY);
+
screenshooter_save_screenshot (screenshot,
1,
- g_strdup (DEFAULT_SAVE_DIRECTORY));
+ home);
+
+ if (home != NULL)
+ g_free (home);
}
else
{
@@ -46,15 +51,20 @@
#ifdef HAVE_GIO
else
{
+ gchar *tempdir = g_strdup (g_get_tmp_dir ());
+
gchar *screenshot_path =
screenshooter_save_screenshot (screenshot,
FALSE,
- g_strdup (g_get_tmp_dir ()));
+ tempdir);
if (screenshot_path != NULL)
{
screenshooter_open_screenshot (screenshot_path, sd->app);
g_free (screenshot_path);
}
+
+ if (tempdir != NULL)
+ g_free (tempdir);
}
#endif
Modified: xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c 2009-01-13 20:10:59 UTC (rev 6452)
+++ xfce4-screenshooter/trunk/lib/screenshooter-dialogs.c 2009-01-13 22:03:49 UTC (rev 6453)
@@ -213,34 +213,46 @@
* @uri: uri of the folder for which the filename should be generated.
* returns: the filename or NULL if *uri == NULL.
*/
-static gchar *generate_filename_for_uri(char *uri)
+static gchar *generate_filename_for_uri (char *uri)
{
- gchar *file_name;
- unsigned int i = 0;
-
- if ( uri == NULL )
+ gboolean exists = TRUE;
+ gchar *filename;
+ gchar *basename;
+ gint i;
+
+ if (uri == NULL)
{
return NULL;
}
+
+ basename = g_strdup (_("Screenshot.png"));
+ filename = g_build_filename (uri, basename, NULL);
- file_name = g_strdup (_("Screenshot.png"));
-
- /* If the plain filename matches the condition, go for it. */
- if (g_access (g_build_filename (uri, file_name, NULL), F_OK) != 0)
+ if (!g_file_test (filename, G_FILE_TEST_EXISTS))
{
- return file_name;
+ g_free (filename);
+
+ return basename;
}
- /* Else, we find the first n that matches the condition */
- do
+ g_free (basename);
+ g_free (filename);
+
+ for (i = 1; exists; ++i)
{
- i++;
- g_free (file_name);
- file_name = g_strdup_printf (_("Screenshot-%d.png"), i);
+ basename = g_strdup_printf (_("Screenshot-%d.png"), i);
+ filename = g_build_filename (uri, basename, NULL);
+
+ if (!g_file_test (filename, G_FILE_TEST_EXISTS))
+ exists = FALSE;
+
+ if (exists)
+ g_free (basename);
+
+ g_free (filename);
}
- while (g_access (g_build_filename (uri, file_name, NULL), F_OK) == 0);
-
- return file_name;
+
+ return basename;
}
Modified: xfce4-screenshooter/trunk/lib/screenshooter-utils.c
===================================================================
--- xfce4-screenshooter/trunk/lib/screenshooter-utils.c 2009-01-13 20:10:59 UTC (rev 6452)
+++ xfce4-screenshooter/trunk/lib/screenshooter-utils.c 2009-01-13 22:03:49 UTC (rev 6453)
@@ -460,7 +460,7 @@
gchar *command =
g_strconcat (application, " ", screenshot_path, NULL);
- GError *error = NULL;
+ GError *error = NULL;
/* Execute the command and show an error dialog if there was
* an error. */
More information about the Goodies-commits
mailing list