From 0285c2984fc1913d583432716d6fff4f9f291994 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Fri, 25 Apr 2003 08:03:15 +0000 Subject: [project @ 2003-04-25 08:03:15 by bursa] Various memory fixes. svn path=/import/netsurf/; revision=128 --- content/fetch.c | 29 +++++++++++--------- content/fetchcache.c | 4 +-- css/css.c | 10 +++---- desktop/browser.c | 6 +++-- render/box.c | 74 ++++++++++++++++++++++++++-------------------------- render/html.c | 32 +++++++++++++---------- 6 files changed, 83 insertions(+), 72 deletions(-) diff --git a/content/fetch.c b/content/fetch.c index 93a0c124d..bbf6b2916 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -1,5 +1,5 @@ /** - * $Id: fetch.c,v 1.6 2003/04/17 21:35:02 bursa Exp $ + * $Id: fetch.c,v 1.7 2003/04/25 08:03:15 bursa Exp $ * * This module handles fetching of data from any url. * @@ -114,7 +114,9 @@ struct fetch * fetch_start(char *url, char *referer, fetch->referer = xstrdup(referer); fetch->p = p; fetch->headers = 0; - fetch->host = xstrdup(uri->server); + fetch->host = 0; + if (uri->server != 0) + fetch->host = xstrdup(uri->server); fetch->queue = 0; fetch->prev = 0; fetch->next = 0; @@ -122,16 +124,19 @@ struct fetch * fetch_start(char *url, char *referer, xmlFreeURI(uri); /* look for a fetch from the same host */ - for (host_fetch = fetch_list; - host_fetch != 0 && strcasecmp(host_fetch->host, fetch->host) != 0; - host_fetch = host_fetch->next) - ; - if (host_fetch != 0) { - /* fetch from this host in progress: queue the new fetch */ - LOG(("queueing")); - fetch->queue = host_fetch->queue; - host_fetch->queue = fetch; - return fetch; + if (fetch->host != 0) { + for (host_fetch = fetch_list; + host_fetch != 0 && (host_fetch->host == 0 || + strcasecmp(host_fetch->host, fetch->host) != 0); + host_fetch = host_fetch->next) + ; + if (host_fetch != 0) { + /* fetch from this host in progress: queue the new fetch */ + LOG(("queueing")); + fetch->queue = host_fetch->queue; + host_fetch->queue = fetch; + return fetch; + } } fetch->next = fetch_list; diff --git a/content/fetchcache.c b/content/fetchcache.c index 34105c71d..600fd13fd 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -1,5 +1,5 @@ /** - * $Id: fetchcache.c,v 1.8 2003/04/17 21:35:02 bursa Exp $ + * $Id: fetchcache.c,v 1.9 2003/04/25 08:03:15 bursa Exp $ */ #include @@ -115,7 +115,7 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size) switch (msg) { case FETCH_TYPE: - mime_type = strdup(data); + mime_type = xstrdup(data); if ((semic = strchr(mime_type, ';')) != 0) *semic = 0; /* remove "; charset=..." */ type = content_lookup(mime_type); diff --git a/css/css.c b/css/css.c index 70e992e15..feea10888 100644 --- a/css/css.c +++ b/css/css.c @@ -1,5 +1,5 @@ /** - * $Id: css.c,v 1.7 2003/04/15 17:53:00 bursa Exp $ + * $Id: css.c,v 1.8 2003/04/25 08:03:15 bursa Exp $ */ #include @@ -111,7 +111,7 @@ void css_process_data(struct content *c, char *data, unsigned long size) buffer = css__scan_bytes(data, size, c->data.css.css->lexer); while ((token = css_lex(c->data.css.css->lexer))) { css_parser_(c->data.css.css->parser, token, - strdup(css_get_text(c->data.css.css->lexer)), + xstrdup(css_get_text(c->data.css.css->lexer)), ¶m); } css__delete_buffer(buffer, c->data.css.css->lexer); @@ -431,16 +431,16 @@ void css_parse_property_list(struct css_style * style, char * str) css_lex_init(&lexer); parser = css_parser_Alloc(malloc); - css_parser_(parser, LBRACE, strdup("{"), ¶m); + css_parser_(parser, LBRACE, xstrdup("{"), ¶m); buffer = css__scan_string(str, lexer); while ((token = css_lex(lexer))) { css_parser_(parser, token, - strdup(css_get_text(lexer)), + xstrdup(css_get_text(lexer)), ¶m); } css__delete_buffer(buffer, lexer); - css_parser_(parser, RBRACE, strdup("}"), ¶m); + css_parser_(parser, RBRACE, xstrdup("}"), ¶m); css_parser_(parser, 0, 0, ¶m); css_parser_Free(parser, free); diff --git a/desktop/browser.c b/desktop/browser.c index 32c9bc659..0a9c674ac 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1,5 +1,5 @@ /** - * $Id: browser.c,v 1.34 2003/04/15 17:53:00 bursa Exp $ + * $Id: browser.c,v 1.35 2003/04/25 08:03:15 bursa Exp $ */ #include "netsurf/content/cache.h" @@ -76,7 +76,9 @@ struct history* history_create(char* desc, char* url) { struct history* h = xcalloc(1, sizeof(struct history)); LOG(("desc = %s, url = %s", desc, url)); - h->description = xstrdup(desc); + h->description = 0; + if (desc != 0) + h->description = xstrdup(desc); h->url = xstrdup(url); LOG(("return h = %p", h)); return h; diff --git a/render/box.c b/render/box.c index 04550a6ec..9e0788fc0 100644 --- a/render/box.c +++ b/render/box.c @@ -1,5 +1,5 @@ /** - * $Id: box.c,v 1.42 2003/04/15 17:53:00 bursa Exp $ + * $Id: box.c,v 1.43 2003/04/25 08:03:15 bursa Exp $ */ #include @@ -223,7 +223,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct content *content, current_textarea = box->gadget; add_gadget_element(elements, box->gadget); textarea_addtext(current_textarea, thistext); - free(content); + xmlFree(content); } else if (strcmp((const char *) n->name, "select") == 0) { LOG(("select")); @@ -237,7 +237,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct content *content, LOG(("option")); current_option = box_option(c, style, current_select); option_addtext(current_option, thistext); - free(content); + xmlFree(content); } } @@ -437,7 +437,7 @@ struct css_style * box_get_style(struct content ** stylesheet, else if (stricmp(s, "center") == 0) style->text_align = CSS_TEXT_ALIGN_CENTER; else if (stricmp(s, "right") == 0) style->text_align = CSS_TEXT_ALIGN_RIGHT; } - free(s); + xmlFree(s); } if ((s = (char *) xmlGetProp(n, (const xmlChar *) "bgcolor"))) { @@ -446,14 +446,14 @@ struct css_style * box_get_style(struct content ** stylesheet, style->background_color = (b << 16) | (g << 8) | r; else if (s[0] != '#') style->background_color = named_colour(s); - free(s); + xmlFree(s); } if ((s = (char *) xmlGetProp(n, (const xmlChar *) "clear"))) { if (stricmp(s, "all") == 0) style->clear = CSS_CLEAR_BOTH; else if (stricmp(s, "left") == 0) style->clear = CSS_CLEAR_LEFT; else if (stricmp(s, "right") == 0) style->clear = CSS_CLEAR_RIGHT; - free(s); + xmlFree(s); } if ((s = (char *) xmlGetProp(n, (const xmlChar *) "color"))) { @@ -462,14 +462,14 @@ struct css_style * box_get_style(struct content ** stylesheet, style->color = (b << 16) | (g << 8) | r; else if (s[0] != '#') style->color = named_colour(s); - free(s); + xmlFree(s); } if ((s = (char *) xmlGetProp(n, (const xmlChar *) "height"))) { style->height.height = CSS_HEIGHT_LENGTH; style->height.length.unit = CSS_UNIT_PX; style->height.length.value = atof(s); - free(s); + xmlFree(s); } if (strcmp((const char *) n->name, "body") == 0) { @@ -479,7 +479,7 @@ struct css_style * box_get_style(struct content ** stylesheet, style->color = (b << 16) | (g << 8) | r; else if (s[0] != '#') style->color = named_colour(s); - free(s); + xmlFree(s); } } @@ -492,7 +492,7 @@ struct css_style * box_get_style(struct content ** stylesheet, style->width.value.length.unit = CSS_UNIT_PX; style->width.value.length.value = atof(s); } - free(s); + xmlFree(s); } if ((s = (char *) xmlGetProp(n, (const xmlChar *) "style"))) { @@ -501,7 +501,7 @@ struct css_style * box_get_style(struct content ** stylesheet, css_parse_property_list(astyle, s); css_cascade(style, astyle); free(astyle); - free(s); + xmlFree(s); } return style; @@ -910,43 +910,43 @@ void gadget_free(struct gui_gadget* g) struct formoption* o; if (g->name != 0) - xfree(g->name); + xmlFree(g->name); switch (g->type) { case GADGET_HIDDEN: if (g->data.hidden.value != 0) - xfree(g->data.hidden.value); + xmlFree(g->data.hidden.value); break; case GADGET_RADIO: if (g->data.checkbox.value != 0) - xfree(g->data.radio.value); + xmlFree(g->data.radio.value); break; case GADGET_CHECKBOX: if (g->data.checkbox.value != 0) - xfree(g->data.checkbox.value); + xmlFree(g->data.checkbox.value); break; case GADGET_TEXTAREA: if (g->data.textarea.text != 0) - xfree(g->data.textarea.text); + xmlFree(g->data.textarea.text); break; case GADGET_TEXTBOX: gui_remove_gadget(g); if (g->data.textbox.text != 0) - xfree(g->data.textbox.text); + xmlFree(g->data.textbox.text); break; case GADGET_ACTIONBUTTON: if (g->data.actionbutt.label != 0) - xfree(g->data.actionbutt.label); + xmlFree(g->data.actionbutt.label); break; case GADGET_SELECT: o = g->data.select.items; while (o != NULL) { if (o->text != 0) - xfree(o->text); + xmlFree(o->text); if (o->value != 0) - xfree(o->value); + xmlFree(o->value); xfree(o); o = o->next; } @@ -988,9 +988,9 @@ void box_free_box(struct box *box) if (box->href != 0) { if (box->parent == 0) - free(box->href); + xmlFree(box->href); else if (box->parent->href != box->href) - free(box->href); + xmlFree(box->href); } } @@ -1024,7 +1024,7 @@ struct box* box_image(xmlNode *n, struct content *content, url = url_join(s, content->url); LOG(("image '%s'", url)); - free(s); + xmlFree(s); /* start fetch */ html_fetch_image(content, url, box); @@ -1052,7 +1052,7 @@ struct box* box_textarea(xmlNode* n, struct css_style* style, struct form* curre if ((s = (char *) xmlGetProp(n, (const xmlChar *) "cols"))) { box->gadget->data.textarea.cols = atoi(s); - free(s); + xmlFree(s); } else box->gadget->data.textarea.cols = 40; @@ -1060,7 +1060,7 @@ struct box* box_textarea(xmlNode* n, struct css_style* style, struct form* curre if ((s = (char *) xmlGetProp(n, (const xmlChar *) "rows"))) { box->gadget->data.textarea.rows = atoi(s); - free(s); + xmlFree(s); } else box->gadget->data.textarea.rows = 16; @@ -1094,7 +1094,7 @@ struct box* box_select(xmlNode * n, struct css_style* style, struct form* curren if ((s = (char *) xmlGetProp(n, (const xmlChar *) "size"))) { box->gadget->data.select.size = atoi(s); - free(s); + xmlFree(s); } else box->gadget->data.select.size = 1; @@ -1139,7 +1139,7 @@ struct formoption* box_option(xmlNode* n, struct css_style* style, struct gui_ga /* TO DO: set selected / value here */ if ((s = (char *) xmlGetProp(n, (const xmlChar *) "selected"))) { option->selected = -1; - free(s); + xmlFree(s); } if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) { @@ -1157,7 +1157,7 @@ void textarea_addtext(struct gui_gadget* textarea, char* text) if (textarea->data.textarea.text == 0) { - textarea->data.textarea.text = strdup(text); + textarea->data.textarea.text = xstrdup(text); } else { @@ -1174,7 +1174,7 @@ void option_addtext(struct formoption* option, char* text) if (option->text == 0) { LOG(("option->text is 0")); - option->text = strdup(text); + option->text = xstrdup(text); } else { @@ -1229,7 +1229,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current box->gadget->data.checkbox.selected = -1; else box->gadget->data.radio.selected = -1; - free(s); + xmlFree(s); } if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) { @@ -1263,7 +1263,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current } else { - box->gadget->data.actionbutt.label = strdup(type); + box->gadget->data.actionbutt.label = xstrdup(type); box->gadget->data.actionbutt.label[0] = toupper(type[0]); } @@ -1276,7 +1276,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current if (!(stricmp(type, "text") == 0 || stricmp(type, "password") == 0)) { - free (type); + xmlFree (type); return box; } @@ -1302,7 +1302,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current if ((s = (char *) xmlGetProp(n, (const xmlChar *) "maxlength"))) { //>>>>>> 1.31 box->gadget->data.textbox.maxlength = atoi(s); - free(s); + xmlFree(s); } #ifdef ARSEMONKEYS @@ -1314,7 +1314,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current box->gadget->data.textbox.size = box->gadget->data.textbox.maxlength; if ((s = (char *) xmlGetProp(n, (const xmlChar *) "size"))) { box->gadget->data.textbox.size = atoi(s); - free(s); + xmlFree(s); } box->gadget->data.textbox.text = xcalloc( @@ -1323,7 +1323,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current if ((s = (char *) xmlGetProp(n, (const xmlChar *) "value"))) { strncpy(box->gadget->data.textbox.text, s, box->gadget->data.textbox.maxlength); - free(s); + xmlFree(s); } if ((s = (char *) xmlGetProp(n, (const xmlChar *) "name"))) { @@ -1331,7 +1331,7 @@ struct box* box_input(xmlNode * n, struct css_style* style, struct form* current } add_gadget_element(elements, box->gadget); - free(type); + xmlFree(type); return box; } @@ -1350,7 +1350,7 @@ struct form* box_form(xmlNode* n) if ((s = (char *) xmlGetProp(n, (const xmlChar *) "method"))) { if (stricmp(s, "post") == 0) form->method = method_POST; - xfree(s); + xmlFree(s); } return form; diff --git a/render/html.c b/render/html.c index 0c60acdb5..8b2cd7338 100644 --- a/render/html.c +++ b/render/html.c @@ -1,5 +1,5 @@ /** - * $Id: html.c,v 1.15 2003/04/15 17:53:00 bursa Exp $ + * $Id: html.c,v 1.16 2003/04/25 08:03:15 bursa Exp $ */ #include @@ -166,7 +166,7 @@ void html_title(struct content *c, xmlNode *head) if (strcmp(node->name, "title") == 0) { title = xmlNodeGetContent(node); c->title = squash_tolat1(title); - free(title); + xmlFree(title); return; } } @@ -203,28 +203,28 @@ void html_find_stylesheets(struct content *c, xmlNode *head) if (!(rel = (char *) xmlGetProp(node, (const xmlChar *) "rel"))) continue; if (strcasecmp(rel, "stylesheet") != 0) { - free(rel); + xmlFree(rel); continue; } - free(rel); + xmlFree(rel); /* type='text/css' or not present */ if ((type = (char *) xmlGetProp(node, (const xmlChar *) "type"))) { if (strcmp(type, "text/css") != 0) { - free(type); + xmlFree(type); continue; } - free(type); + xmlFree(type); } /* media contains 'screen' or 'all' or not present */ if ((media = (char *) xmlGetProp(node, (const xmlChar *) "media"))) { if (strstr(media, "screen") == 0 && strstr(media, "all") == 0) { - free(media); + xmlFree(media); continue; } - free(media); + xmlFree(media); } /* href='...' */ @@ -233,7 +233,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head) url = url_join(href, c->url); LOG(("linked stylesheet %i '%s'", i, url)); - free(href); + xmlFree(href); /* start fetch */ c->data.html.stylesheet_content = xrealloc(c->data.html.stylesheet_content, @@ -252,19 +252,19 @@ void html_find_stylesheets(struct content *c, xmlNode *head) if (!(type = (char *) xmlGetProp(node, (const xmlChar *) "type"))) continue; if (strcmp(type, "text/css") != 0) { - free(type); + xmlFree(type); continue; } - free(type); + xmlFree(type); /* media contains 'screen' or 'all' or not present */ if ((media = (char *) xmlGetProp(node, (const xmlChar *) "media"))) { if (strstr(media, "screen") == 0 && strstr(media, "all") == 0) { - free(media); + xmlFree(media); continue; } - free(media); + xmlFree(media); } /* create stylesheet */ @@ -278,7 +278,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head) data = xmlNodeGetContent(node2); content_process_data(c->data.html.stylesheet_content[1], data, strlen(data)); - free(data); + xmlFree(data); } } } @@ -439,14 +439,18 @@ void html_destroy(struct content *c) unsigned int i; LOG(("content %p", c)); + LOG(("layout %p", c->data.html.layout)); if (c->data.html.layout != 0) box_free(c->data.html.layout); + LOG(("fonts %p", c->data.html.fonts)); if (c->data.html.fonts != 0) font_free_set(c->data.html.fonts); + LOG(("title %p", c->title)); if (c->title != 0) xfree(c->title); for (i = 0; i != c->data.html.object_count; i++) { + LOG(("object %i %p", i, c->data.html.object[i].content)); if (c->data.html.object[i].content != 0) cache_free(c->data.html.object[i].content); free(c->data.html.object[i].url); -- cgit v1.2.3