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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <gtk/gtk.h> 5 #include <gtk/gtk.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 namespace { 9 namespace {
10 10
(...skipping 10 matching lines...) Expand all
21 gdk_atom_intern("TARGETS", false)); 21 gdk_atom_intern("TARGETS", false));
22 if (!target_data) { 22 if (!target_data) {
23 printf("failed to get the contents!\n"); 23 printf("failed to get the contents!\n");
24 return; 24 return;
25 } 25 }
26 26
27 gtk_selection_data_get_targets(target_data, &targets, &num_targets); 27 gtk_selection_data_get_targets(target_data, &targets, &num_targets);
28 28
29 printf("%d available targets:\n---------------\n", num_targets); 29 printf("%d available targets:\n---------------\n", num_targets);
30 30
31 gboolean target_omitted;
32 gchar* target_name;
Evan Stade 2013/05/09 04:46:06 no reason for these to be declared outside the for
31 for (int i = 0; i < num_targets; i++) { 33 for (int i = 0; i < num_targets; i++) {
32 printf(" [format: %s", gdk_atom_name(targets[i])); 34 target_name = gdk_atom_name(targets[i]);
35 printf(" [format: %s", target_name);
33 GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, targets[i]); 36 GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, targets[i]);
34 if (!data) { 37 if (!data) {
35 printf("]: NULL\n\n"); 38 printf("]: NULL\n\n");
39 g_free(target_name);
Evan Stade 2013/05/09 04:46:06 just copy it into a std::string and free right awa
36 continue; 40 continue;
37 } 41 }
38 42
39 printf(" / length: %d / bits %d]: ", data->length, data->format); 43 printf(" / length: %d / bits %d]: ", data->length, data->format);
40 44
41 if (strstr(gdk_atom_name(targets[i]), "image")) { 45 if (strstr(target_name, "image")) {
42 printf("(image omitted)\n\n"); 46 printf("(image omitted)\n\n");
43 continue; 47 target_omitted = true;
44 } else if (strstr(gdk_atom_name(targets[i]), "TIMESTAMP")) { 48 } else if (strstr(target_name, "TIMESTAMP")) {
45 // TODO(estade): Print the time stamp in human readable format. 49 // TODO(estade): Print the time stamp in human readable format.
46 printf("(time omitted)\n\n"); 50 printf("(time omitted)\n\n");
51 target_omitted = true;
52 } else
Evan Stade 2013/05/09 04:46:06 curlies
53 target_omitted = false;
54
55 g_free(target_name);
56 if (target_omitted) {
57 gtk_selection_data_free(data);
47 continue; 58 continue;
48 } 59 }
49 60
50 for (int j = 0; j < data->length; j++) { 61 for (int j = 0; j < data->length; j++) {
Evan Stade 2013/05/09 04:46:06 just put all of this inside the else case
51 // Output data one byte at a time. Currently wide strings look 62 // Output data one byte at a time. Currently wide strings look
52 // pretty weird. 63 // pretty weird.
53 printf("%c", (data->data[j] == 0 ? '_' : data->data[j])); 64 printf("%c", (data->data[j] == 0 ? '_' : data->data[j]));
54 } 65 }
55 printf("\n\n"); 66 printf("\n\n");
67 gtk_selection_data_free(data);
56 } 68 }
57 69
58 if (num_targets <= 0) { 70 if (num_targets <= 0) {
59 printf("No targets advertised. Text is: "); 71 printf("No targets advertised. Text is: ");
60 gchar* text = gtk_clipboard_wait_for_text(clip); 72 gchar* text = gtk_clipboard_wait_for_text(clip);
61 printf("%s\n", text ? text : "NULL"); 73 printf("%s\n", text ? text : "NULL");
62 g_free(text); 74 g_free(text);
63 } 75 }
64 76
65 g_free(targets); 77 g_free(targets);
78 gtk_selection_data_free(target_data);
66 } 79 }
67 80
68 } 81 }
69 82
70 /* Small program to dump the contents of GTK's clipboards to the terminal. 83 /* Small program to dump the contents of GTK's clipboards to the terminal.
71 * Feel free to add to it or improve formatting or whatnot. 84 * Feel free to add to it or improve formatting or whatnot.
72 */ 85 */
73 int main(int argc, char* argv[]) { 86 int main(int argc, char* argv[]) {
74 gtk_init(&argc, &argv); 87 gtk_init(&argc, &argv);
75 88
76 printf("Desktop clipboard\n"); 89 printf("Desktop clipboard\n");
77 PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); 90 PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
78 91
79 printf("X clipboard\n"); 92 printf("X clipboard\n");
80 PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_PRIMARY)); 93 PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
81 } 94 }
OLDNEW
« 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