Fix several memory leaks in gtk_clipboard_dump utility.

BUG=

Review URL: https://chromiumcodereview.appspot.com/14917015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199945 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc b/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc
index c96ee00..4ddf1a2 100644
--- a/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc
+++ b/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc
@@ -5,6 +5,7 @@
 #include <gtk/gtk.h>
 #include <stdio.h>
 #include <string.h>
+#include <string>
 
 namespace {
 
@@ -29,7 +30,10 @@
   printf("%d available targets:\n---------------\n", num_targets);
 
   for (int i = 0; i < num_targets; i++) {
-    printf("  [format: %s", gdk_atom_name(targets[i]));
+    gchar* target_name_cstr = gdk_atom_name(targets[i]);
+    std::string target_name(target_name_cstr);
+    g_free(target_name_cstr);
+    printf("  [format: %s", target_name.c_str());
     GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, targets[i]);
     if (!data) {
       printf("]: NULL\n\n");
@@ -38,21 +42,20 @@
 
     printf(" / length: %d / bits %d]: ", data->length, data->format);
 
-    if (strstr(gdk_atom_name(targets[i]), "image")) {
+    if (strstr(target_name.c_str(), "image")) {
       printf("(image omitted)\n\n");
-      continue;
-    } else if (strstr(gdk_atom_name(targets[i]), "TIMESTAMP")) {
+    } else if (strstr(target_name.c_str(), "TIMESTAMP")) {
       // TODO(estade): Print the time stamp in human readable format.
       printf("(time omitted)\n\n");
-      continue;
+    } else {
+      for (int j = 0; j < data->length; j++) {
+        // Output data one byte at a time. Currently wide strings look
+        // pretty weird.
+        printf("%c", (data->data[j] == 0 ? '_' : data->data[j]));
+      }
+      printf("\n\n");
     }
-
-    for (int j = 0; j < data->length; j++) {
-      // Output data one byte at a time. Currently wide strings look
-      // pretty weird.
-      printf("%c", (data->data[j] == 0 ? '_' : data->data[j]));
-    }
-    printf("\n\n");
+    gtk_selection_data_free(data);
   }
 
   if (num_targets <= 0) {
@@ -63,6 +66,7 @@
   }
 
   g_free(targets);
+  gtk_selection_data_free(target_data);
 }
 
 }