logo

badwolf

minimalist and privacy-oriented web browser based on WebKitGTK git clone https://hacktivis.me/git/badwolf.git
commit: b3426f0fe4b262bda2473ad142e5099f0436e5dd
parent 401c239d9be8d9162fd4459eb195bfd5b91369d1
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 17 Jun 2019 06:36:00 +0200

Bugfix: don't abort on malloc failure

Diffstat:

Mbadwolf.c14+++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/badwolf.c b/badwolf.c @@ -531,9 +531,11 @@ SearchEntryCb_stop__search(GtkSearchEntry *search, gpointer user_data) struct Client * new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view) { - struct Client *browser = g_malloc(sizeof(struct Client)); + struct Client *browser = g_try_malloc(sizeof(struct Client)); target_url = ensure_uri_scheme(target_url, (related_web_view == NULL)); + if(browser == NULL) return NULL; + browser->window = window; browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); browser->toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); @@ -644,12 +646,21 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web return browser; } +/* badwolf_new_tab: Inserts struct Client *browser in GtkNotebook *notebook + * + * returns: + * 0 : Ran successfully + * -1 : Failed to insert a page for browser->box + * -2 : browser is NULL + */ int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser) { gint current_page = gtk_notebook_get_current_page(notebook); gchar *title = _("New tab"); + if(browser == NULL) return -2; + gtk_widget_show_all(browser->box); if(gtk_notebook_insert_page(notebook, browser->box, NULL, (current_page + 2)) == -1) @@ -710,6 +721,7 @@ get_tab_position(GtkContainer *notebook, GtkWidget *child) int main(int argc, char *argv[]) { + // getting an abort if this one fails to alloc struct Window *window = g_malloc(sizeof(struct Client)); gchar *target_url = NULL;