Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Unified Diff: tools/gtk_clipboard_dump/gtk_clipboard_dump.cc

Issue 14917015: Fix several memory leaks in gtk_clipboard_dump utility. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gtk_clipboard_dump/gtk_clipboard_dump.cc
diff --git a/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc b/tools/gtk_clipboard_dump/gtk_clipboard_dump.cc
index c96ee0083693da327190e572246883d8bf7be3a4..4ddf1a2a73af7d806314a2bc93a45f6e3938386f 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 @@ void PrintClipboardContents(GtkClipboard* clip) {
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 @@ void PrintClipboardContents(GtkClipboard* clip) {
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;
- }
-
- 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]));
+ } 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");
}
- printf("\n\n");
+ gtk_selection_data_free(data);
}
if (num_targets <= 0) {
@@ -63,6 +66,7 @@ void PrintClipboardContents(GtkClipboard* clip) {
}
g_free(targets);
+ gtk_selection_data_free(target_data);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698