[epiphany/mcatanzaro/#1092] session: improve robustness when parsing session
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/mcatanzaro/#1092] session: improve robustness when parsing session
- Date: Sun, 9 Feb 2020 19:13:09 +0000 (UTC)
commit 735fea54d3e2f6324901dfd357ad52c686a8fa5e
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Feb 9 12:41:02 2020 -0600
session: improve robustness when parsing session
This is a second try at 32ecc861. This time, account for the fact that
EphyWindow can be destroyed at the GTK level even if it still has an
outstanding ref, and that will cause the last ref of the GtkNotebook to
be destroyed. So instead of holding a ref, let's check for window
destruction instead.
We should also account for the possibility that the session state is
malformed, listing <window> or <embed> tags in nonsensical places.
Previously, the correctness of this code relied on valid input. Now, we
should be robust to problematic input.
Lastly, note 32ecc861 had introduced a memory leak, because
context->window was set to NULL in session_end_element() without an
unref.
Fixes #1092
src/ephy-session.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
---
diff --git a/src/ephy-session.c b/src/ephy-session.c
index 3a4139736..bb3a78e4c 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -1100,6 +1100,11 @@ session_parser_context_free (SessionParserContext *context)
{
g_object_unref (context->session);
+ if (context->window) {
+ /* This should only happen if the session state is malformed. */
+ g_signal_handlers_disconnect_by_data (context->window, context);
+ }
+
g_free (context);
}
@@ -1111,7 +1116,13 @@ session_parse_window (SessionParserContext *context,
GdkRectangle geometry = { -1, -1, 0, 0 };
guint i;
+ if (context->window) {
+ /* This should only happen if the session state is malformed. */
+ return;
+ }
+
context->window = ephy_window_new ();
+ g_signal_connect (context->window, "destroy", gtk_widget_destroyed, &context->window);
for (i = 0; names[i]; i++) {
gulong int_value;
@@ -1154,6 +1165,13 @@ session_parse_embed (SessionParserContext *context,
gboolean is_pin = FALSE;
guint i;
+ if (!context->window) {
+ /* This can happen if the session is malformed, or if the window is
+ * destroyed before the session finishes loading.
+ */
+ return;
+ }
+
notebook = ephy_window_get_notebook (context->window);
for (i = 0; names[i]; i++) {
@@ -1283,6 +1301,13 @@ session_end_element (GMarkupParseContext *ctx,
GtkWidget *notebook;
EphyEmbedShell *shell = ephy_embed_shell_get_default ();
+ if (!context->window) {
+ /* This can happen if the session is malformed, or if the window is
+ * destroyed before the session finishes loading.
+ */
+ return;
+ }
+
notebook = ephy_window_get_notebook (context->window);
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), context->active_tab);
@@ -1297,6 +1322,7 @@ session_end_element (GMarkupParseContext *ctx,
ephy_embed_shell_restored_window (shell);
+ g_signal_handlers_disconnect_by_data (context->window, context);
context->window = NULL;
context->active_tab = 0;
context->is_first_window = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]