[Xfce4-commits] <xfce4-screenshooter:master> Do not free values that are not owned by the callee.

Jérôme Guelfucci noreply at xfce.org
Sun Oct 11 19:34:01 CEST 2009


Updating branch refs/heads/master
         to aa668e027fa2c72b730d752ad357d4bb1887acfa (commit)
       from 9f1dfbeae19b94d694298f20015c8da04c3ef04c (commit)

commit aa668e027fa2c72b730d752ad357d4bb1887acfa
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date:   Sun Oct 11 19:35:08 2009 +0200

    Do not free values that are not owned by the callee.
    
    Thanks to Jannis Pohlmann for the detailed explanations.

 lib/screenshooter-actions.c |   15 ++++++++++++++-
 lib/screenshooter-zimagez.c |   17 ++++++++---------
 lib/screenshooter-zimagez.h |    3 ++-
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/lib/screenshooter-actions.c b/lib/screenshooter-actions.c
index 623e4bf..304ae37 100644
--- a/lib/screenshooter-actions.c
+++ b/lib/screenshooter-actions.c
@@ -101,7 +101,20 @@ gboolean screenshooter_action_idle (ScreenshotData *sd)
           if (sd->action == OPEN)
             screenshooter_open_screenshot (screenshot_path, sd->app);
           else
-            screenshooter_upload_to_zimagez (screenshot_path, &sd->last_user, sd->title);
+            {
+              gchar *new_last_user = NULL;
+
+              screenshooter_upload_to_zimagez (screenshot_path,
+                                               sd->last_user,
+                                               &new_last_user,
+                                               sd->title);
+
+              if (new_last_user)
+                {
+                  g_free (sd->last_user);
+                  sd->last_user = new_last_user;
+                }
+            }
         }
 
       g_object_unref (temp_dir);
diff --git a/lib/screenshooter-zimagez.c b/lib/screenshooter-zimagez.c
index cda72f1..975fa48 100644
--- a/lib/screenshooter-zimagez.c
+++ b/lib/screenshooter-zimagez.c
@@ -904,6 +904,7 @@ static void cb_image_uploaded (ScreenshooterJob *job, gchar *upload_name, gchar
   gchar *last_user_temp;
 
   g_return_if_fail (upload_name != NULL);
+  g_return_if_fail (last_user == NULL || *last_user == NULL);
 
   image_url = g_strdup_printf ("http://www.zimagez.com/zimage/%s.php", upload_name);
   thumbnail_url =
@@ -922,10 +923,6 @@ static void cb_image_uploaded (ScreenshooterJob *job, gchar *upload_name, gchar
   bb_code =
     g_strdup_printf ("[url=%s]\n  [img]%s[/img]\n[/url]", image_url, thumbnail_url);
 
-  /* Set the last user */
-  if (*last_user != NULL)
-    g_free (*last_user);
-
   last_user_temp = g_object_get_data (G_OBJECT (job), "user");
 
   if (last_user_temp == NULL)
@@ -1153,9 +1150,10 @@ static void cb_update_info (ExoJob *job, gchar *message, GtkWidget *label)
  * Last user is updated with the given user name if the upload was successful.
  **/
 
-void screenshooter_upload_to_zimagez (const gchar *image_path,
-                                      gchar       **last_user,
-                                      gchar       *title)
+void screenshooter_upload_to_zimagez (const gchar  *image_path,
+                                      gchar        *last_user,
+                                      gchar       **new_last_user,
+                                      gchar        *title)
 {
   ScreenshooterJob *job;
   GtkWidget *dialog;
@@ -1164,6 +1162,7 @@ void screenshooter_upload_to_zimagez (const gchar *image_path,
   GtkWidget *main_box, *main_alignment;
 
   g_return_if_fail (image_path != NULL);
+  g_return_if_fail (new_last_user == NULL || *new_last_user == NULL);
 
   dialog =
     gtk_dialog_new_with_buttons (_("ZimageZ"),
@@ -1210,10 +1209,10 @@ void screenshooter_upload_to_zimagez (const gchar *image_path,
 
   gtk_widget_show_all (GTK_DIALOG(dialog)->vbox);
 
-  job = zimagez_upload_to_zimagez (image_path, *last_user, title);
+  job = zimagez_upload_to_zimagez (image_path, last_user, title);
 
   g_signal_connect (job, "ask", (GCallback) cb_ask_for_information, NULL);
-  g_signal_connect (job, "image-uploaded", (GCallback) cb_image_uploaded, last_user);
+  g_signal_connect (job, "image-uploaded", (GCallback) cb_image_uploaded, new_last_user);
   g_signal_connect (job, "error", (GCallback) cb_error, NULL);
   g_signal_connect (job, "finished", (GCallback) cb_finished, dialog);
   g_signal_connect (job, "info-message", (GCallback) cb_update_info, label);
diff --git a/lib/screenshooter-zimagez.h b/lib/screenshooter-zimagez.h
index da0558d..d6ed50f 100644
--- a/lib/screenshooter-zimagez.h
+++ b/lib/screenshooter-zimagez.h
@@ -34,7 +34,8 @@
 #include "katze-throbber.h"
 
 void screenshooter_upload_to_zimagez (const gchar  *image_path,
-                                      gchar       **last_user,
+                                      gchar        *last_user,
+                                      gchar       **new_last_user,
                                       gchar        *title);
 
 



More information about the Xfce4-commits mailing list