After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 606280 - Brought down to its kness when something causes ~/.gtk-bookmarks to be very big
Brought down to its kness when something causes ~/.gtk-bookmarks to be very big
Status: RESOLVED FIXED
Product: gnome-panel
Classification: Other
Component: panel
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Panel Maintainers
Panel Maintainers
Depends on:
Blocks:
 
 
Reported: 2010-01-07 01:54 UTC by Gustavo Noronha (kov)
Modified: 2010-01-12 12:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
impose a hard limit on the number of entries read from ~/.gtk-bookmarks (4.35 KB, patch)
2010-01-07 01:55 UTC, Gustavo Noronha (kov)
needs-work Details | Review
second version (4.24 KB, patch)
2010-01-09 12:42 UTC, Gustavo Noronha (kov)
committed Details | Review

Description Gustavo Noronha (kov) 2010-01-07 01:54:00 UTC
Originally reported here:

https://bugs.launchpad.net/ubuntu/+source/gnome-panel/+bug/503868

gnome panel handles big bookmarks files quite badly; I think we should impose a hard limit to keep gnome panel working even if a misbehaving application, or a misguided user fill up ~/.gtk-bookmarks.
Comment 1 Gustavo Noronha (kov) 2010-01-07 01:55:06 UTC
Created attachment 150947 [details] [review]
impose a hard limit on the number of entries read from ~/.gtk-bookmarks
Comment 2 Vincent Untz 2010-01-09 00:57:15 UTC
Review of attachment 150947 [details] [review]:

::: gnome-panel/panel-menu-items.c
@@ +375,3 @@
+
+	if (error) {
+		g_error_free (error);

Since you don't use the content of the error there, just pass NULL to g_io_channel_new, and check if io_channel is NULL or not.

@@ +387,3 @@
+		gsize     length;
+		gsize     terminator_pos;
+		GIOStatus status;

Small nitpick: length/terminator_pos/status should be aligned with contents (not *contents), so add a space ;-)

@@ +396,3 @@
+			break;
+		} else if (status != G_IO_STATUS_NORMAL)
+			break;

Just do:

if (status != G_IO_STATUS_NORMAL)
    break;

(which means you can pass NULL as error to g_io_channel_read_line)

@@ +403,3 @@
+		if (terminator_pos > 0)
+			contents[terminator_pos] = '\0';
+

Hrm, do we really need to do this?

@@ +404,3 @@
+			contents[terminator_pos] = '\0';
+
+		g_debug("contents: %s", contents);

Please remove the g_debug()

@@ +420,3 @@
 
+	for (l = lines; l; l = l->next) {
+		char *line = (char*)l->data;

Nitpick: "(char *) l->data;" (add a space after the cast)

@@ +462,3 @@
 		}
+
+		g_free (line);

Hrm, doesn't this break the g_hash_table_lookup() call in case you have the same string again? You shouldn't free the memory now, but after the loop (with a g_slist_foreach() call).
Comment 3 Gustavo Noronha (kov) 2010-01-09 12:42:42 UTC
Created attachment 151089 [details] [review]
second version

Thanks for the review! Here's another version.
Comment 4 Gustavo Noronha (kov) 2010-01-09 12:44:14 UTC
(In reply to comment #2)
> @@ +403,3 @@
> +        if (terminator_pos > 0)
> +            contents[terminator_pos] = '\0';
> +
> 
> Hrm, do we really need to do this?

The string read with g_io_channel_read_line contains the \n, which we do not want, so yeah.
Comment 5 Vincent Untz 2010-01-12 11:08:52 UTC
Review of attachment 151089 [details] [review]:

Please commit with the three changes below, thanks!

::: gnome-panel/panel-menu-items.c
@@ +371,3 @@
 				     BOOKMARKS_FILENAME, NULL);
 
+	io_channel = g_io_channel_new_file (filename, "r", &error);

s/&error/NULL/ else you're leaking the error in case of error ;-)

@@ +391,3 @@
+		if (status != G_IO_STATUS_NORMAL)
+			break;
+		else if (length == 0)

Small nitpick: can you just remove the else here? It doesn't matter, but I find it a tiny bit more readable without it.

@@ +396,3 @@
+		/* Clear the line terminator, if any */
+		if (terminator_pos > 0)
+			contents[terminator_pos] = '\0';

Thanks for the explanation for this! Maybe clarify with the comment:
/* Clear the \n line terminator */
Comment 6 Gustavo Noronha (kov) 2010-01-12 12:10:26 UTC
Comment on attachment 151089 [details] [review]
second version

OK! Pushed 5ff272ab5dbdfd3a0c259e333a9dfe006ed0e431 to master with the fixes. Thanks for the reviews!