diff options
author | Christian Grothoff <christian@grothoff.org> | 2007-08-25 01:59:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2007-08-25 01:59:15 +0000 |
commit | 3c60805e9e6a363f7dbfd8b2160fb38b0deb7b73 (patch) | |
tree | 893bb168507609b97a7f13699ae4132715b64c0b /src/plugins/peers/peers.c | |
parent | 724fec1e069a0cdd7550de27cfab458a24636536 (diff) | |
download | gnunet-gtk-3c60805e9e6a363f7dbfd8b2160fb38b0deb7b73.tar.gz gnunet-gtk-3c60805e9e6a363f7dbfd8b2160fb38b0deb7b73.zip |
fixing some memory leaks
Diffstat (limited to 'src/plugins/peers/peers.c')
-rw-r--r-- | src/plugins/peers/peers.c | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/src/plugins/peers/peers.c b/src/plugins/peers/peers.c index 9e5cbac0..26374e8b 100644 --- a/src/plugins/peers/peers.c +++ b/src/plugins/peers/peers.c | |||
@@ -50,6 +50,14 @@ static GdkPixbuf *red; | |||
50 | 50 | ||
51 | static GdkPixbuf *black; | 51 | static GdkPixbuf *black; |
52 | 52 | ||
53 | struct Flags { | ||
54 | struct Flags * next; | ||
55 | char * cc; | ||
56 | GdkPixbuf * flag; | ||
57 | }; | ||
58 | |||
59 | static struct Flags * flags; | ||
60 | |||
53 | static int | 61 | static int |
54 | collector (void *data, | 62 | collector (void *data, |
55 | const PeerIdentity * identity, | 63 | const PeerIdentity * identity, |
@@ -72,6 +80,7 @@ collector (void *data, | |||
72 | cron_t now; | 80 | cron_t now; |
73 | int i; | 81 | int i; |
74 | int found; | 82 | int found; |
83 | struct Flags * pos; | ||
75 | 84 | ||
76 | hash2enc (&identity->hashPubKey, &enc); | 85 | hash2enc (&identity->hashPubKey, &enc); |
77 | /* check if same peer is already in model! */ | 86 | /* check if same peer is already in model! */ |
@@ -128,21 +137,36 @@ collector (void *data, | |||
128 | cc = NULL; | 137 | cc = NULL; |
129 | if (cc != NULL) | 138 | if (cc != NULL) |
130 | { | 139 | { |
131 | cc = STRDUP (cc); | 140 | pos = flags; |
132 | for (i = 0; i < strlen (cc); i++) | 141 | while (pos != NULL) { |
133 | cc[i] = tolower (cc[i]); | 142 | if (0 == strcmp(pos->cc, cc)) { |
134 | dir = os_get_installation_path (IPK_DATADIR); | 143 | flagBuf = pos->flag; |
135 | fn = MALLOC (strlen (dir) + 32); | 144 | break; |
136 | strcpy (fn, dir); | 145 | } |
137 | strcat (fn, | 146 | pos = pos->next; |
138 | DIR_SEPARATOR_STR ".." | 147 | } |
139 | DIR_SEPARATOR_STR "gnunet-gtk" | 148 | if (pos == NULL) { |
140 | DIR_SEPARATOR_STR "flags" DIR_SEPARATOR_STR); | 149 | cc = STRDUP (cc); |
141 | strcat (fn, cc); | 150 | for (i = 0; i < strlen (cc); i++) |
142 | strcat (fn, ".png"); | 151 | cc[i] = tolower (cc[i]); |
143 | FREE (dir); | 152 | dir = os_get_installation_path (IPK_DATADIR); |
144 | flagBuf = gdk_pixbuf_new_from_file (fn, NULL); | 153 | fn = MALLOC (strlen (dir) + 32); |
145 | FREE (fn); | 154 | strcpy (fn, dir); |
155 | strcat (fn, | ||
156 | DIR_SEPARATOR_STR ".." | ||
157 | DIR_SEPARATOR_STR "gnunet-gtk" | ||
158 | DIR_SEPARATOR_STR "flags" DIR_SEPARATOR_STR); | ||
159 | strcat (fn, cc); | ||
160 | strcat (fn, ".png"); | ||
161 | FREE (dir); | ||
162 | flagBuf = gdk_pixbuf_new_from_file (fn, NULL); | ||
163 | FREE (fn); | ||
164 | pos = MALLOC(sizeof(struct Flags)); | ||
165 | pos->cc = cc; | ||
166 | pos->flag = flagBuf; | ||
167 | pos->next = flags; | ||
168 | flags = pos; | ||
169 | } | ||
146 | } | 170 | } |
147 | FREE (prefix); | 171 | FREE (prefix); |
148 | 172 | ||
@@ -156,8 +180,6 @@ collector (void *data, | |||
156 | ledBuf = red; | 180 | ledBuf = red; |
157 | else | 181 | else |
158 | ledBuf = black; | 182 | ledBuf = black; |
159 | if (ledBuf != NULL) | ||
160 | g_object_ref (ledBuf); | ||
161 | 183 | ||
162 | /* add to model */ | 184 | /* add to model */ |
163 | if (found == NO) | 185 | if (found == NO) |
@@ -169,7 +191,6 @@ collector (void *data, | |||
169 | 2, bpmFromPeer, | 191 | 2, bpmFromPeer, |
170 | 3, (const char *) &enc, | 192 | 3, (const char *) &enc, |
171 | 4, ledBuf, 5, flagBuf, 6, cc, 7, last_message, -1); | 193 | 4, ledBuf, 5, flagBuf, 6, cc, 7, last_message, -1); |
172 | FREENONNULL (cc); | ||
173 | FREE (hostname); | 194 | FREE (hostname); |
174 | return OK; | 195 | return OK; |
175 | } | 196 | } |
@@ -366,6 +387,9 @@ init_peers (struct GE_Context *e, struct GC_Configuration *c) | |||
366 | void | 387 | void |
367 | done_peers () | 388 | done_peers () |
368 | { | 389 | { |
390 | GtkWidget *w; | ||
391 | struct Flags * pos; | ||
392 | |||
369 | cron_del_job (cron, &updatePeerInfo, REFRESH_RATE, NULL); | 393 | cron_del_job (cron, &updatePeerInfo, REFRESH_RATE, NULL); |
370 | if (red != NULL) | 394 | if (red != NULL) |
371 | g_object_unref (red); | 395 | g_object_unref (red); |
@@ -375,6 +399,17 @@ done_peers () | |||
375 | g_object_unref (black); | 399 | g_object_unref (black); |
376 | if (yellow != NULL) | 400 | if (yellow != NULL) |
377 | g_object_unref (yellow); | 401 | g_object_unref (yellow); |
402 | w = glade_xml_get_widget (getMainXML (), "peersTreeView"); | ||
403 | gtk_tree_view_set_model (GTK_TREE_VIEW (w), NULL); | ||
404 | |||
405 | while (flags != NULL) { | ||
406 | pos = flags->next; | ||
407 | if (flags->flag != NULL) | ||
408 | g_object_unref(flags->flag); | ||
409 | FREE (flags->cc); | ||
410 | FREE(flags); | ||
411 | flags = pos; | ||
412 | } | ||
378 | } | 413 | } |
379 | 414 | ||
380 | 415 | ||