diff options
-rw-r--r-- | amiga/dt_anim.c | 7 | ||||
-rw-r--r-- | amiga/dt_picture.c | 7 | ||||
-rw-r--r-- | amiga/dt_sound.c | 7 | ||||
-rw-r--r-- | amiga/icon.c | 7 | ||||
-rw-r--r-- | amiga/plugin_hack.c | 7 | ||||
-rw-r--r-- | cocoa/apple_image.m | 9 | ||||
-rw-r--r-- | content/content.c | 47 | ||||
-rw-r--r-- | content/content_protected.h | 4 | ||||
-rw-r--r-- | css/css.c | 9 | ||||
-rw-r--r-- | image/bmp.c | 9 | ||||
-rw-r--r-- | image/gif.c | 9 | ||||
-rw-r--r-- | image/ico.c | 9 | ||||
-rw-r--r-- | image/jpeg.c | 7 | ||||
-rw-r--r-- | image/mng.c | 9 | ||||
-rw-r--r-- | image/nssprite.c | 7 | ||||
-rw-r--r-- | image/png.c | 18 | ||||
-rw-r--r-- | image/rsvg.c | 9 | ||||
-rw-r--r-- | image/svg.c | 9 | ||||
-rw-r--r-- | image/video.c | 9 | ||||
-rw-r--r-- | image/webp.c | 7 | ||||
-rw-r--r-- | javascript/content.c | 7 | ||||
-rw-r--r-- | render/box_construct.c | 114 | ||||
-rw-r--r-- | render/box_normalise.c | 17 | ||||
-rw-r--r-- | render/html.c | 98 | ||||
-rw-r--r-- | render/html_internal.h | 2 | ||||
-rw-r--r-- | render/layout.c | 4 | ||||
-rw-r--r-- | render/textplain.c | 41 | ||||
-rw-r--r-- | riscos/content-handlers/artworks.c | 7 | ||||
-rw-r--r-- | riscos/content-handlers/draw.c | 7 | ||||
-rw-r--r-- | riscos/content-handlers/sprite.c | 7 |
30 files changed, 277 insertions, 233 deletions
diff --git a/amiga/dt_anim.c b/amiga/dt_anim.c index 9d79257cc..221f331fb 100644 --- a/amiga/dt_anim.c +++ b/amiga/dt_anim.c @@ -29,7 +29,6 @@ #include "image/bitmap.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include <proto/datatypes.h> #include <proto/dos.h> @@ -139,14 +138,14 @@ nserror amiga_dt_anim_create(const content_handler *handler, amiga_dt_anim_content *plugin; nserror error; - plugin = talloc_zero(0, amiga_dt_anim_content); + plugin = calloc(1, sizeof(amiga_dt_anim_content)); if (plugin == NULL) return NSERROR_NOMEM; error = content__init(&plugin->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(plugin); + free(plugin); return error; } @@ -309,7 +308,7 @@ nserror amiga_dt_anim_clone(const struct content *old, struct content **newc) LOG(("amiga_dt_anim_clone")); - plugin = talloc_zero(0, amiga_dt_anim_content); + plugin = calloc(1, sizeof(amiga_dt_anim_content)); if (plugin == NULL) return NSERROR_NOMEM; diff --git a/amiga/dt_picture.c b/amiga/dt_picture.c index 076847989..1a9dc4f72 100644 --- a/amiga/dt_picture.c +++ b/amiga/dt_picture.c @@ -29,7 +29,6 @@ #include "image/image_cache.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include <proto/datatypes.h> #include <proto/dos.h> @@ -104,14 +103,14 @@ nserror amiga_dt_picture_create(const content_handler *handler, struct content *adt; nserror error; - adt = talloc_zero(0, struct content); + adt = calloc(1, sizeof(struct content)); if (adt == NULL) return NSERROR_NOMEM; error = content__init(adt, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(adt); + free(adt); return error; } @@ -231,7 +230,7 @@ nserror amiga_dt_picture_clone(const struct content *old, struct content **newc) LOG(("amiga_dt_picture_clone")); - adt = talloc_zero(0, struct content); + adt = calloc(1, sizeof(struct content)); if (adt == NULL) return NSERROR_NOMEM; diff --git a/amiga/dt_sound.c b/amiga/dt_sound.c index d1e9771f3..3f8216914 100644 --- a/amiga/dt_sound.c +++ b/amiga/dt_sound.c @@ -28,7 +28,6 @@ #include "render/box.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include <proto/datatypes.h> #include <proto/dos.h> @@ -126,14 +125,14 @@ nserror amiga_dt_sound_create(const content_handler *handler, LOG(("amiga_dt_sound_create")); - plugin = talloc_zero(0, amiga_dt_sound_content); + plugin = calloc(1, sizeof(amiga_dt_sound_content)); if (plugin == NULL) return NSERROR_NOMEM; error = content__init(&plugin->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(plugin); + free(plugin); return error; } @@ -251,7 +250,7 @@ nserror amiga_dt_sound_clone(const struct content *old, struct content **newc) LOG(("amiga_dt_sound_clone")); - plugin = talloc_zero(0, amiga_dt_sound_content); + plugin = calloc(1, sizeof(amiga_dt_sound_content)); if (plugin == NULL) return NSERROR_NOMEM; diff --git a/amiga/icon.c b/amiga/icon.c index 87a8a5c18..641095bc4 100644 --- a/amiga/icon.c +++ b/amiga/icon.c @@ -44,7 +44,6 @@ #include "content/content_protected.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" #include "utils/url.h" @@ -108,14 +107,14 @@ nserror amiga_icon_create(const content_handler *handler, amiga_icon_content *ai_content; nserror error; - ai_content = talloc_zero(0, amiga_icon_content); + ai_content = calloc(1, sizeof(amiga_icon_content)); if (ai_content == NULL) return NSERROR_NOMEM; error = content__init(&ai_content->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(ai_content); + free(ai_content); return error; } @@ -285,7 +284,7 @@ nserror amiga_icon_clone(const struct content *old, struct content **newc) amiga_icon_content *ai; nserror error; - ai = talloc_zero(0, amiga_icon_content); + ai = calloc(1, sizeof(amiga_icon_content)); if (ai == NULL) return NSERROR_NOMEM; diff --git a/amiga/plugin_hack.c b/amiga/plugin_hack.c index 89e80e3e4..830d2f614 100644 --- a/amiga/plugin_hack.c +++ b/amiga/plugin_hack.c @@ -27,7 +27,6 @@ #include "desktop/plotters.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include <proto/dos.h> #include <proto/exec.h> @@ -101,14 +100,14 @@ nserror amiga_plugin_hack_create(const content_handler *handler, amiga_plugin_hack_content *plugin; nserror error; - plugin = talloc_zero(0, amiga_plugin_hack_content); + plugin = calloc(1, amiga_plugin_hack_content); if (plugin == NULL) return NSERROR_NOMEM; error = content__init(&plugin->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(plugin); + free(plugin); return error; } @@ -208,7 +207,7 @@ nserror amiga_plugin_hack_clone(const struct content *old, struct content **newc LOG(("amiga_plugin_hack_clone")); - plugin = talloc_zero(0, amiga_plugin_hack_content); + plugin = calloc(1, sizeof(amiga_plugin_hack_content)); if (plugin == NULL) return NSERROR_NOMEM; diff --git a/cocoa/apple_image.m b/cocoa/apple_image.m index f28ec25bf..ab17f8ab4 100644 --- a/cocoa/apple_image.m +++ b/cocoa/apple_image.m @@ -24,7 +24,6 @@ #include "content/content_protected.h" #include "image/bitmap.h" #include "desktop/plotters.h" -#include "utils/talloc.h" #include "utils/utils.h" #include "utils/schedule.h" @@ -113,14 +112,14 @@ nserror apple_image_create(const content_handler *handler, apple_image_content *ai; nserror error; - ai = talloc_zero(0, apple_image_content); + ai = calloc(1, sizeof(apple_image_content)); if (ai == NULL) return NSERROR_NOMEM; error = content__init(&ai->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(ai); + free(ai); return error; } @@ -188,7 +187,7 @@ bool apple_image_convert(struct content *c) if (frames > 1) { ai->frames = frames; ai->currentFrame = 0; - ai->frameTimes = talloc_zero_array( ai, int, ai->frames ); + ai->frameTimes = calloc( ai->frames , sizeof(int)); for (NSUInteger i = 0; i < frames; i++) { [image setProperty: NSImageCurrentFrame withValue: [NSNumber numberWithUnsignedInteger: i]]; ai->frameTimes[i] = 100 * [[image valueForProperty: NSImageCurrentFrameDuration] floatValue]; @@ -217,7 +216,7 @@ nserror apple_image_clone(const struct content *old, struct content **newc) apple_image_content *ai_old = (apple_image_content *)old; nserror error; - ai = talloc_zero(0, apple_image_content); + ai = calloc(1, sizeof(apple_image_content)); if (ai == NULL) return NSERROR_NOMEM; diff --git a/content/content.c b/content/content.c index b65e110ec..353abeeb0 100644 --- a/content/content.c +++ b/content/content.c @@ -44,7 +44,6 @@ #include "utils/http.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" #define URL_FMT_SPC "%.140s" @@ -64,7 +63,7 @@ static void content_convert(struct content *c); /** * Initialise a new content structure. * - * \param c Content to initialise (allocated with talloc) + * \param c Content to initialise * \param handler Content handler * \param imime_type MIME type of content * \param params HTTP parameters @@ -85,14 +84,16 @@ nserror content__init(struct content *c, const content_handler *handler, LOG(("url "URL_FMT_SPC" -> %p", nsurl_access(llcache_handle_get_url(llcache)), c)); - user_sentinel = talloc(c, struct content_user); + user_sentinel = calloc(1, sizeof(struct content_user)); if (user_sentinel == NULL) { return NSERROR_NOMEM; } - c->fallback_charset = talloc_strdup(c, fallback_charset); - if (fallback_charset != NULL && c->fallback_charset == NULL) { - return NSERROR_NOMEM; + if (fallback_charset != NULL) { + c->fallback_charset = strdup(fallback_charset); + if (c->fallback_charset == NULL) { + return NSERROR_NOMEM; + } } c->llcache = llcache; @@ -396,7 +397,22 @@ void content_destroy(struct content *c) link = content__free_rfc5988_link(link); } - talloc_free(c); + /* free the user list */ + if (c->user_list != NULL) { + free(c->user_list); + } + + /* free the title */ + if (c->title != NULL) { + free(c->title); + } + + /* free the fallback characterset */ + if (c->fallback_charset != NULL) { + free(c->fallback_charset); + } + + free(c); } @@ -558,7 +574,7 @@ bool content_add_user(struct content *c, LOG(("content "URL_FMT_SPC" (%p), user %p %p", nsurl_access(llcache_handle_get_url(c->llcache)), c, callback, pw)); - user = talloc(c, struct content_user); + user = malloc(sizeof(struct content_user)); if (!user) return false; user->callback = callback; @@ -599,7 +615,7 @@ void content_remove_user(struct content *c, } next = user->next; user->next = next->next; - talloc_free(next); + free(next); } /** @@ -779,12 +795,12 @@ void content_add_error(struct content *c, const char *token, bool content__set_title(struct content *c, const char *title) { - char *new_title = talloc_strdup(c, title); + char *new_title = strdup(title); if (new_title == NULL) return false; if (c->title != NULL) - talloc_free(c->title); + free(c->title); c->title = new_title; @@ -1253,7 +1269,7 @@ struct content *content_clone(struct content *c) * Clone a content's data members * * \param c Content to clone - * \param nc Content to populate (allocated with talloc) + * \param nc Content to populate * \return NSERROR_OK on success, appropriate error otherwise */ nserror content__clone(const struct content *c, struct content *nc) @@ -1261,7 +1277,7 @@ nserror content__clone(const struct content *c, struct content *nc) struct content_user *user_sentinel; nserror error; - user_sentinel = talloc_zero(c, struct content_user); + user_sentinel = calloc(1, sizeof(struct content_user)); if (user_sentinel == NULL) { return NSERROR_NOMEM; } @@ -1285,7 +1301,7 @@ nserror content__clone(const struct content *c, struct content *nc) nc->quirks = c->quirks; if (c->fallback_charset != NULL) { - nc->fallback_charset = talloc_strdup(nc, c->fallback_charset); + nc->fallback_charset = strdup(c->fallback_charset); if (nc->fallback_charset == NULL) { return NSERROR_NOMEM; } @@ -1301,10 +1317,9 @@ nserror content__clone(const struct content *c, struct content *nc) nc->time = c->time; nc->reformat_time = c->reformat_time; nc->size = c->size; - nc->talloc_size = c->talloc_size; if (c->title != NULL) { - nc->title = talloc_strdup(nc, c->title); + nc->title = strdup(c->title); if (nc->title == NULL) { return NSERROR_NOMEM; } diff --git a/content/content_protected.h b/content/content_protected.h index 36a053b56..e39979768 100644 --- a/content/content_protected.h +++ b/content/content_protected.h @@ -122,9 +122,7 @@ struct content { page's objects. */ unsigned int size; /**< Estimated size of all data - associated with this content, except - alloced as talloc children of this. */ - off_t talloc_size; /**< Used by content_clean() */ + associated with this content */ char *title; /**< Title for browser window. */ unsigned int active; /**< Number of child fetches or conversions currently in progress. */ @@ -32,7 +32,6 @@ #include "utils/http.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" /* Define to trace import fetches */ #undef NSCSS_IMPORT_TRACE @@ -102,14 +101,14 @@ nserror nscss_create(const content_handler *handler, union content_msg_data msg_data; nserror error; - result = talloc_zero(0, nscss_content); + result = calloc(1, sizeof(nscss_content)); if (result == NULL) return NSERROR_NOMEM; error = content__init(&result->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(result); + free(result); return error; } @@ -133,7 +132,7 @@ nserror nscss_create(const content_handler *handler, content_broadcast(&result->base, CONTENT_MSG_ERROR, msg_data); if (charset_value != NULL) lwc_string_unref(charset_value); - talloc_free(result); + free(result); return error; } @@ -340,7 +339,7 @@ nserror nscss_clone(const struct content *old, struct content **newc) unsigned long size; nserror error; - new_css = talloc_zero(0, nscss_content); + new_css = calloc(1, sizeof(nscss_content)); if (new_css == NULL) return NSERROR_NOMEM; diff --git a/image/bmp.c b/image/bmp.c index aea6d26fc..9ca86fd82 100644 --- a/image/bmp.c +++ b/image/bmp.c @@ -33,7 +33,6 @@ #include "desktop/plotters.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" #include "image/bitmap.h" @@ -72,20 +71,20 @@ static nserror nsbmp_create(const content_handler *handler, nsbmp_content *bmp; nserror error; - bmp = talloc_zero(0, nsbmp_content); + bmp = calloc(1, sizeof(nsbmp_content)); if (bmp == NULL) return NSERROR_NOMEM; error = content__init(&bmp->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(bmp); + free(bmp); return error; } error = nsbmp_create_bmp_data(bmp); if (error != NSERROR_OK) { - talloc_free(bmp); + free(bmp); return error; } @@ -214,7 +213,7 @@ static nserror nsbmp_clone(const struct content *old, struct content **newc) nsbmp_content *new_bmp; nserror error; - new_bmp = talloc_zero(0, nsbmp_content); + new_bmp = calloc(1, sizeof(nsbmp_content)); if (new_bmp == NULL) return NSERROR_NOMEM; diff --git a/image/gif.c b/image/gif.c index d92eede85..b3781f837 100644 --- a/image/gif.c +++ b/image/gif.c @@ -45,7 +45,6 @@ #include "utils/log.h" #include "utils/messages.h" #include "utils/schedule.h" -#include "utils/talloc.h" #include "utils/utils.h" typedef struct nsgif_content { @@ -105,20 +104,20 @@ static nserror nsgif_create(const content_handler *handler, nsgif_content *result; nserror error; - result = talloc_zero(0, nsgif_content); + result = calloc(1, sizeof(nsgif_content)); if (result == NULL) return NSERROR_NOMEM; error = content__init(&result->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(result); + free(result); return error; } error = nsgif_create_gif_data(result); if (error != NSERROR_OK) { - talloc_free(result); + free(result); return error; } @@ -367,7 +366,7 @@ static nserror nsgif_clone(const struct content *old, struct content **newc) nsgif_content *gif; nserror error; - gif = talloc_zero(0, nsgif_content); + gif = calloc(1, sizeof(nsgif_content)); if (gif == NULL) return NSERROR_NOMEM; diff --git a/image/ico.c b/image/ico.c index 65a85c2d4..b9abd7d1c 100644 --- a/image/ico.c +++ b/image/ico.c @@ -35,7 +35,6 @@ #include "image/image.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" typedef struct nsico_content { @@ -69,20 +68,20 @@ static nserror nsico_create(const content_handler *handler, nsico_content *result; nserror error; - result = talloc_zero(0, nsico_content); + result = calloc(1, sizeof(nsico_content)); if (result == NULL) return NSERROR_NOMEM; error = content__init(&result->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(result); + free(result); return error; } error = nsico_create_ico_data(result); if (error != NSERROR_OK) { - talloc_free(result); + free(result); return error; } @@ -190,7 +189,7 @@ static nserror nsico_clone(const struct content *old, struct content **newc) nsico_content *ico; nserror error; - ico = talloc_zero(0, nsico_content); + ico = calloc(1, sizeof(nsico_content)); if (ico == NULL) return NSERROR_NOMEM; diff --git a/image/jpeg.c b/image/jpeg.c index 27d79bb11..82fde0dd1 100644 --- a/image/jpeg.c +++ b/image/jpeg.c @@ -35,7 +35,6 @@ #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/types.h" #include "utils/utils.h" @@ -72,14 +71,14 @@ static nserror nsjpeg_create(const content_handler *handler, struct content *jpeg; nserror error; - jpeg = talloc_zero(0, struct content); + jpeg = calloc(1, sizeof(struct content)); if (jpeg == NULL) return NSERROR_NOMEM; error = content__init(jpeg, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(jpeg); + free(jpeg); return error; } @@ -347,7 +346,7 @@ static nserror nsjpeg_clone(const struct content *old, struct content **newc) struct content *jpeg_c; nserror error; - jpeg_c = talloc_zero(0, struct content); + jpeg_c = calloc(1, sizeof(struct content)); if (jpeg_c == NULL) return NSERROR_NOMEM; diff --git a/image/mng.c b/image/mng.c index 8d9769b70..67625f026 100644 --- a/image/mng.c +++ b/image/mng.c @@ -35,7 +35,6 @@ #include "utils/log.h" #include "utils/messages.h" #include "utils/schedule.h" -#include "utils/talloc.h" #include "utils/utils.h" /* This implementation does not currently support dynamic MNGs or any @@ -513,20 +512,20 @@ static nserror nsmng_create(const content_handler *handler, nsmng_content *mng; nserror error; - mng = talloc_zero(0, nsmng_content); + mng = calloc(1, sizeof(nsmng_content)); if (mng == NULL) return NSERROR_NOMEM; error = content__init(&mng->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(mng); + free(mng); return error; } error = nsmng_create_mng_data(mng); if (error != NSERROR_OK) { - talloc_free(mng); + free(mng); return error; } @@ -728,7 +727,7 @@ static nserror nsmng_clone(const struct content *old, struct content **newc) const char *data; unsigned long size; - mng = talloc_zero(0, nsmng_content); + mng = calloc(1, sizeof(nsmng_content)); if (mng == NULL) return NSERROR_NOMEM; diff --git a/image/nssprite.c b/image/nssprite.c index a83d94378..ea05c8fe0 100644 --- a/image/nssprite.c +++ b/image/nssprite.c @@ -32,7 +32,6 @@ #include "image/nssprite.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" typedef struct nssprite_content { @@ -68,14 +67,14 @@ static nserror nssprite_create(const content_handler *handler, nssprite_content *sprite; nserror error; - sprite = talloc_zero(0, nssprite_content); + sprite = calloc(1, sizeof(nssprite_content)); if (sprite == NULL) return NSERROR_NOMEM; error = content__init(&sprite->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(sprite); + free(sprite); return error; } @@ -199,7 +198,7 @@ static nserror nssprite_clone(const struct content *old, struct content **newc) nssprite_content *sprite; nserror error; - sprite = talloc_zero(0, nssprite_content); + sprite = calloc(1, sizeof(nssprite_content)); if (sprite == NULL) return NSERROR_NOMEM; diff --git a/image/png.c b/image/png.c index 829eee272..6f1d926ee 100644 --- a/image/png.c +++ b/image/png.c @@ -35,7 +35,6 @@ #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" /* accommodate for old versions of libpng (beware security holes!) */ @@ -291,20 +290,25 @@ static nserror nspng_create(const content_handler *handler, nspng_content *png_c; nserror error; - png_c = talloc_zero(0, nspng_content); + png_c = calloc(1, sizeof(nspng_content)); if (png_c == NULL) return NSERROR_NOMEM; - error = content__init(&png_c->base, handler, imime_type, params, - llcache, fallback_charset, quirks); + error = content__init(&png_c->base, + handler, + imime_type, + params, + llcache, + fallback_charset, + quirks); if (error != NSERROR_OK) { - talloc_free(png_c); + free(png_c); return error; } error = nspng_create_png_data(png_c); if (error != NSERROR_OK) { - talloc_free(png_c); + free(png_c); return error; } @@ -542,7 +546,7 @@ static nserror nspng_clone(const struct content *old_c, struct content **new_c) const char *data; unsigned long size; - clone_png_c = talloc_zero(0, nspng_content); + clone_png_c = calloc(1, sizeof(nspng_content)); if (clone_png_c == NULL) return NSERROR_NOMEM; diff --git a/image/rsvg.c b/image/rsvg.c index d70364703..2e41fdd59 100644 --- a/image/rsvg.c +++ b/image/rsvg.c @@ -41,7 +41,6 @@ #include "utils/log.h" #include "utils/utils.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "image/rsvg.h" @@ -82,20 +81,20 @@ static nserror rsvg_create(const content_handler *handler, rsvg_content *svg; nserror error; - svg = talloc_zero(0, rsvg_content); + svg = calloc(1, sizeof(rsvg_content)); if (svg == NULL) return NSERROR_NOMEM; error = content__init(&svg->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(svg); + free(svg); return error; } error = rsvg_create_svg_data(svg); if (error != NSERROR_OK) { - talloc_free(svg); + free(svg); return error; } @@ -252,7 +251,7 @@ static nserror rsvg_clone(const struct content *old, struct content **newc) const char *data; unsigned long size; - svg = talloc_zero(0, rsvg_content); + svg = calloc(1, sizeof(rsvg_content)); if (svg == NULL) return NSERROR_NOMEM; diff --git a/image/svg.c b/image/svg.c index 5e21c84c5..971ab764e 100644 --- a/image/svg.c +++ b/image/svg.c @@ -30,7 +30,6 @@ #include "desktop/plotters.h" #include "image/svg.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" typedef struct svg_content { @@ -73,20 +72,20 @@ static nserror svg_create(const content_handler *handler, svg_content *svg; nserror error; - svg = talloc_zero(0, svg_content); + svg = calloc(1, sizeof(svg_content)); if (svg == NULL) return NSERROR_NOMEM; error = content__init(&svg->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(svg); + free(svg); return error; } error = svg_create_svg_data(svg); if (error != NSERROR_OK) { - talloc_free(svg); + free(svg); return error; } @@ -290,7 +289,7 @@ static nserror svg_clone(const struct content *old, struct content **newc) svg_content *svg; nserror error; - svg = talloc_zero(0, svg_content); + svg = calloc(1, sizeof(svg_content)); if (svg == NULL) return NSERROR_NOMEM; diff --git a/image/video.c b/image/video.c index 2255208c3..1cbbeebf0 100644 --- a/image/video.c +++ b/image/video.c @@ -21,7 +21,6 @@ #include "content/content_factory.h" #include "content/content_protected.h" #include "image/video.h" -#include "utils/talloc.h" typedef struct nsvideo_content { struct content base; @@ -76,26 +75,26 @@ static nserror nsvideo_create(const content_handler *handler, nserror error; GstBus *bus; - video = talloc_zero(0, nsvideo_content); + video = calloc(1, sizeof(nsvideo_content)); if (video == NULL) return NSERROR_NOMEM; error = content__init(&video->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(video); + free(video); return error; } error = llcache_handle_force_stream(llcache); if (error != NSERROR_OK) { - talloc_free(video); + free(video); return error; } video->playbin = gst_element_factory_make("playbin2", NULL); if (video->playbin == NULL) { - talloc_free(video); + free(video); return NSERROR_NOMEM; } diff --git a/image/webp.c b/image/webp.c index eba155492..080cf8bb0 100644 --- a/image/webp.c +++ b/image/webp.c @@ -30,7 +30,6 @@ #include "content/content_protected.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" typedef struct webp_content @@ -49,14 +48,14 @@ static nserror webp_create(const content_handler *handler, webp_content *webp; nserror error; - webp = talloc_zero(0, webp_content); + webp = calloc(1, sizeof(webp_content)); if (webp == NULL) return NSERROR_NOMEM; error = content__init(&webp->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(webp); + free(webp); return error; } @@ -169,7 +168,7 @@ static nserror webp_clone(const struct content *old, struct content **newc) webp_content *webp; nserror error; - webp = talloc_zero(0, webp_content); + webp = calloc(1, sizeof(webp_content)); if (webp == NULL) return NSERROR_NOMEM; diff --git a/javascript/content.c b/javascript/content.c index 879c2190d..ef1bedc8e 100644 --- a/javascript/content.c +++ b/javascript/content.c @@ -30,7 +30,6 @@ #include "content/hlcache.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" #include "javascript/content.h" @@ -46,14 +45,14 @@ static nserror javascript_create(const content_handler *handler, javascript_content *script; nserror error; - script = talloc_zero(0, javascript_content); + script = calloc(1, sizeof(javascript_content)); if (script == NULL) return NSERROR_NOMEM; error = content__init(&script->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(script); + free(script); return error; } @@ -76,7 +75,7 @@ javascript_clone(const struct content *old, struct content **newc) javascript_content *script; nserror error; - script = talloc_zero(0, javascript_content); + script = calloc(1, sizeof(javascript_content)); if (script == NULL) return NSERROR_NOMEM; diff --git a/render/box_construct.c b/render/box_construct.c index 23896717f..c34c0af96 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -60,6 +60,8 @@ struct box_construct_ctx { struct box *root_box; /**< Root box in the tree */ box_construct_complete_cb cb; /**< Callback to invoke on completion */ + + int *bctx; /**< talloc context */ }; /** @@ -162,6 +164,14 @@ bool xml_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb) { struct box_construct_ctx *ctx; + if (c->bctx == NULL) { + /* create a context allocation for this box tree */ + c->bctx = talloc_zero(0, int); + if (c->bctx == NULL) { + return false; + } + } + ctx = malloc(sizeof(*ctx)); if (ctx == NULL) return false; @@ -170,6 +180,7 @@ bool xml_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb) ctx->n = dom_node_ref(n); ctx->root_box = NULL; ctx->cb = cb; + ctx->bctx = c->bctx; schedule(0, (schedule_callback_fn) convert_xml_to_box, ctx); @@ -568,13 +579,13 @@ void convert_xml_to_box(struct box_construct_ctx *ctx) * \return True on success, false on memory exhaustion */ static bool box_construct_marker(struct box *box, const char *title, - html_content *content, struct box *parent) + struct box_construct_ctx *ctx, struct box *parent) { lwc_string *image_uri; struct box *marker; marker = box_create(NULL, box->style, false, NULL, NULL, title, - NULL, content); + NULL, ctx->bctx); if (marker == false) return false; @@ -629,7 +640,7 @@ static bool box_construct_marker(struct box *box, const char *title, } } - marker->text = talloc_array(content, char, 20); + marker->text = talloc_array(ctx->bctx, char, 20); if (marker->text == NULL) return false; @@ -656,8 +667,8 @@ static bool box_construct_marker(struct box *box, const char *title, if (error != NSERROR_OK) return false; - if (html_fetch_object(content, url, marker, image_types, - content->base.available_width, 1000, false) == + if (html_fetch_object(ctx->content, url, marker, image_types, + ctx->content->base.available_width, 1000, false) == false) { nsurl_unref(url); return false; @@ -709,7 +720,7 @@ static void box_construct_generate(dom_node *n, html_content *content, /** \todo Not wise to drop const from the computed style */ gen = box_create(NULL, (css_computed_style *) style, - false, NULL, NULL, NULL, NULL, content); + false, NULL, NULL, NULL, NULL, content->bctx); if (gen == NULL) { return; } @@ -859,7 +870,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, if (t == NULL) return false; - props.title = talloc_strdup(ctx->content, t); + props.title = talloc_strdup(ctx->bctx, t); free(t); @@ -882,7 +893,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, box = box_create(styles, styles->styles[CSS_PSEUDO_ELEMENT_NONE], false, props.href, props.target, props.title, id, - ctx->content); + ctx->bctx); if (box == NULL) return false; @@ -1001,7 +1012,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, "Root box must not be inline or floated"); props.inline_container = box_create(NULL, NULL, false, NULL, - NULL, NULL, NULL, ctx->content); + NULL, NULL, NULL, ctx->bctx); if (props.inline_container == NULL) return false; @@ -1048,7 +1059,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, if (css_computed_display(box->style, props.node_is_root) == CSS_DISPLAY_LIST_ITEM) { /* List item: compute marker */ - if (box_construct_marker(box, props.title, ctx->content, + if (box_construct_marker(box, props.title, ctx, props.containing_block) == false) return false; } @@ -1059,7 +1070,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, /* Float: insert a float between the parent and box. */ struct box *flt = box_create(NULL, NULL, false, props.href, props.target, props.title, - NULL, ctx->content); + NULL, ctx->bctx); if (flt == NULL) return false; @@ -1118,7 +1129,7 @@ void box_construct_element_after(dom_node *n, html_content *content) if (props.inline_container == NULL) { /* Create inline container if we don't have one */ props.inline_container = box_create(NULL, NULL, false, - NULL, NULL, NULL, NULL, content); + NULL, NULL, NULL, NULL, content->bctx); if (props.inline_container == NULL) return; @@ -1131,7 +1142,7 @@ void box_construct_element_after(dom_node *n, html_content *content) inline_end = box_create(NULL, box->style, false, box->href, box->target, box->title, box->id == NULL ? NULL : - lwc_string_ref(box->id), content); + lwc_string_ref(box->id), content->bctx); if (inline_end != NULL) { inline_end->type = BOX_INLINE_END; @@ -1206,7 +1217,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) * (i.e. this box is the first child of its parent, or * was preceded by block-level siblings) */ props.inline_container = box_create(NULL, NULL, false, - NULL, NULL, NULL, NULL, ctx->content); + NULL, NULL, NULL, NULL, ctx->bctx); if (props.inline_container == NULL) { free(text); return false; @@ -1222,7 +1233,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) box = box_create(NULL, (css_computed_style *) props.parent_style, false, props.href, props.target, props.title, - NULL, ctx->content); + NULL, ctx->bctx); if (box == NULL) { free(text); return false; @@ -1230,7 +1241,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) box->type = BOX_TEXT; - box->text = talloc_strdup(ctx->content, text); + box->text = talloc_strdup(ctx->bctx, text); free(text); if (box->text == NULL) return false; @@ -1324,7 +1335,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) * siblings) */ props.inline_container = box_create(NULL, NULL, false, NULL, NULL, NULL, NULL, - ctx->content); + ctx->bctx); if (props.inline_container == NULL) { free(text); return false; @@ -1341,7 +1352,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) box = box_create(NULL, (css_computed_style *) props.parent_style, false, props.href, props.target, props.title, - NULL, ctx->content); + NULL, ctx->bctx); if (box == NULL) { free(text); return false; @@ -1349,7 +1360,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) box->type = BOX_TEXT; - box->text = talloc_strdup(ctx->content, current); + box->text = talloc_strdup(ctx->bctx, current); if (box->text == NULL) { free(text); return false; @@ -1367,7 +1378,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) /* Linebreak: create new inline container */ props.inline_container = box_create(NULL, NULL, false, NULL, NULL, NULL, NULL, - ctx->content); + ctx->bctx); if (props.inline_container == NULL) { free(text); return false; @@ -1656,7 +1667,7 @@ bool box_a(BOX_SPECIAL_PARAMS) else { /* 6.16 says that frame names must begin with [a-zA-Z] * This doesn't match reality, so just take anything */ - box->target = talloc_strdup(content, + box->target = talloc_strdup(content->bctx, dom_string_data(s)); if (!box->target) { dom_string_unref(s); @@ -1697,7 +1708,7 @@ bool box_image(BOX_SPECIAL_PARAMS) dom_string_unref(s); if (alt == NULL) return false; - box->text = talloc_strdup(content, alt); + box->text = talloc_strdup(content->bctx, alt); free(alt); if (box->text == NULL) return false; @@ -1802,7 +1813,7 @@ bool box_object(BOX_SPECIAL_PARAMS) if (box->usemap && box->usemap[0] == '#') box->usemap++; - params = talloc(content, struct object_params); + params = talloc(content->bctx, struct object_params); if (params == NULL) return false; @@ -2035,11 +2046,11 @@ bool box_frameset(BOX_SPECIAL_PARAMS) return true; } - content->frameset = talloc_zero(content, struct content_html_frames); + content->frameset = talloc_zero(content->bctx, struct content_html_frames); if (!content->frameset) return false; - ok = box_create_frameset(content->frameset, n, content); + ok = box_create_frameset(content->frameset, n, content->bctx); if (ok) box->type = BOX_NONE; @@ -2402,7 +2413,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS) } /* create a new iframe */ - iframe = talloc(content, struct content_html_iframe); + iframe = talloc(content->bctx, struct content_html_iframe); if (iframe == NULL) { nsurl_unref(url); return false; @@ -2425,7 +2436,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS) /* fill in specified values */ err = dom_element_get_attribute(n, kstr_name, &s); if (err == DOM_NO_ERR && s != NULL) { - iframe->name = talloc_strdup(content, dom_string_data(s)); + iframe->name = talloc_strdup(content->bctx, dom_string_data(s)); dom_string_unref(s); } @@ -2533,30 +2544,31 @@ bool box_input(BOX_SPECIAL_PARAMS) goto no_memory; inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, - content); + content->bctx); if (inline_container == NULL) goto no_memory; inline_container->type = BOX_INLINE_CONTAINER; inline_box = box_create(NULL, box->style, false, 0, 0, - box->title, 0, content); + box->title, 0, content->bctx); if (inline_box == NULL) goto no_memory; inline_box->type = BOX_TEXT; if (box->gadget->value != NULL) - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, box->gadget->value); else if (box->gadget->type == GADGET_SUBMIT) - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, messages_get("Form_Submit")); else if (box->gadget->type == GADGET_RESET) - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, messages_get("Form_Reset")); else - inline_box->text = talloc_strdup(content, "Button"); + inline_box->text = talloc_strdup(content->bctx, + "Button"); if (inline_box->text == NULL) goto no_memory; @@ -2631,18 +2643,18 @@ bool box_input_text(BOX_SPECIAL_PARAMS, bool password) box->type = BOX_INLINE_BLOCK; - inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content); + inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content->bctx); if (!inline_container) return false; inline_container->type = BOX_INLINE_CONTAINER; inline_box = box_create(NULL, box->style, false, 0, 0, box->title, 0, - content); + content->bctx); if (!inline_box) return false; inline_box->type = BOX_TEXT; if (password) { inline_box->length = strlen(box->gadget->value); - inline_box->text = talloc_array(content, char, + inline_box->text = talloc_array(content->bctx, char, inline_box->length + 1); if (!inline_box->text) return false; @@ -2654,7 +2666,7 @@ bool box_input_text(BOX_SPECIAL_PARAMS, bool password) char *text = cnv_space2nbsp(box->gadget->value); if (!text) return false; - inline_box->text = talloc_strdup(content, text); + inline_box->text = talloc_strdup(content->bctx, text); free(text); if (!inline_box->text) return false; @@ -2795,12 +2807,12 @@ bool box_select(BOX_SPECIAL_PARAMS) box->gadget = gadget; gadget->box = box; - inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content); + inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content->bctx); if (inline_container == NULL) goto no_memory; inline_container->type = BOX_INLINE_CONTAINER; inline_box = box_create(NULL, box->style, false, 0, 0, box->title, 0, - content); + content->bctx); if (inline_box == NULL) goto no_memory; inline_box->type = BOX_TEXT; @@ -2816,13 +2828,13 @@ bool box_select(BOX_SPECIAL_PARAMS) } if (gadget->data.select.num_selected == 0) - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, messages_get("Form_None")); else if (gadget->data.select.num_selected == 1) - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, gadget->data.select.current->text); else - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, messages_get("Form_Many")); if (inline_box->text == NULL) goto no_memory; @@ -2927,7 +2939,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS) box->gadget->box = box; inline_container = box_create(NULL, 0, false, 0, 0, box->title, 0, - content); + content->bctx); if (inline_container == NULL) return false; inline_container->type = BOX_INLINE_CONTAINER; @@ -2947,7 +2959,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS) while (true) { /* BOX_TEXT */ len = strcspn(current, "\r\n"); - s = talloc_strndup(content, current, len); + s = talloc_strndup(content->bctx, current, len); if (s == NULL) { if (area_data != NULL) dom_string_unref(area_data); @@ -2955,7 +2967,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS) } inline_box = box_create(NULL, box->style, false, 0, 0, - box->title, 0, content); + box->title, 0, content->bctx); if (inline_box == NULL) { if (area_data != NULL) dom_string_unref(area_data); @@ -2973,7 +2985,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS) /* BOX_BR */ br_box = box_create(NULL, box->style, false, 0, 0, box->title, - 0, content); + 0, content->bctx); if (br_box == NULL) { if (area_data != NULL) dom_string_unref(area_data); @@ -3015,7 +3027,7 @@ bool box_embed(BOX_SPECIAL_PARAMS) box_is_root(n)) == CSS_DISPLAY_NONE) return true; - params = talloc(content, struct object_params); + params = talloc(content->bctx, struct object_params); if (params == NULL) return false; @@ -3086,7 +3098,7 @@ bool box_embed(BOX_SPECIAL_PARAMS) return false; } - param = talloc(content, struct object_param); + param = talloc(content->bctx, struct object_param); if (param == NULL) { dom_string_unref(value); dom_string_unref(name); @@ -3094,10 +3106,10 @@ bool box_embed(BOX_SPECIAL_PARAMS) return false; } - param->name = talloc_strdup(content, dom_string_data(name)); - param->value = talloc_strdup(content, dom_string_data(value)); + param->name = talloc_strdup(content->bctx, dom_string_data(name)); + param->value = talloc_strdup(content->bctx, dom_string_data(value)); param->type = NULL; - param->valuetype = talloc_strdup(content, "data"); + param->valuetype = talloc_strdup(content->bctx, "data"); param->next = NULL; dom_string_unref(value); diff --git a/render/box_normalise.c b/render/box_normalise.c index 8428b8455..42b20cbb7 100644 --- a/render/box_normalise.c +++ b/render/box_normalise.c @@ -32,7 +32,6 @@ #include "render/html_internal.h" #include "render/table.h" #include "utils/log.h" -#include "utils/talloc.h" /* Define to enable box normalise debug */ #undef BOX_NORMALISE_DEBUG @@ -163,7 +162,7 @@ bool box_normalise_block(struct box *block, html_content *c) return false; table = box_create(NULL, style, true, block->href, - block->target, NULL, NULL, c); + block->target, NULL, NULL, c->bctx); if (table == NULL) { css_computed_style_destroy(style); return false; @@ -267,7 +266,7 @@ bool box_normalise_table(struct box *table, html_content * c) } row_group = box_create(NULL, style, true, table->href, - table->target, NULL, NULL, c); + table->target, NULL, NULL, c->bctx); if (row_group == NULL) { css_computed_style_destroy(style); free(col_info.spans); @@ -354,7 +353,7 @@ bool box_normalise_table(struct box *table, html_content * c) } row_group = box_create(NULL, style, true, table->href, - table->target, NULL, NULL, c); + table->target, NULL, NULL, c->bctx); if (row_group == NULL) { css_computed_style_destroy(style); free(col_info.spans); @@ -371,7 +370,7 @@ bool box_normalise_table(struct box *table, html_content * c) } row = box_create(NULL, style, true, row_group->href, - row_group->target, NULL, NULL, c); + row_group->target, NULL, NULL, c->bctx); if (row == NULL) { css_computed_style_destroy(style); box_free(row_group); @@ -491,7 +490,7 @@ bool box_normalise_table_spans(struct box *table, struct span_info *spans, cell = box_create(NULL, style, true, table_row->href, table_row->target, - NULL, NULL, c); + NULL, NULL, c->bctx); if (cell == NULL) { css_computed_style_destroy( style); @@ -598,7 +597,7 @@ bool box_normalise_table_row_group(struct box *row_group, return false; row = box_create(NULL, style, true, row_group->href, - row_group->target, NULL, NULL, c); + row_group->target, NULL, NULL, c->bctx); if (row == NULL) { css_computed_style_destroy(style); return false; @@ -674,7 +673,7 @@ bool box_normalise_table_row_group(struct box *row_group, } row = box_create(NULL, style, true, row_group->href, - row_group->target, NULL, NULL, c); + row_group->target, NULL, NULL, c->bctx); if (row == NULL) { css_computed_style_destroy(style); return false; @@ -743,7 +742,7 @@ bool box_normalise_table_row(struct box *row, return false; cell = box_create(NULL, style, true, row->href, - row->target, NULL, NULL, c); + row->target, NULL, NULL, c->bctx); if (cell == NULL) { css_computed_style_destroy(style); return false; diff --git a/render/html.c b/render/html.c index 7be2dabe5..b6aabb6a3 100644 --- a/render/html.c +++ b/render/html.c @@ -93,7 +93,7 @@ static void html_destroy_objects(html_content *html) } html->object_list = victim->next; - talloc_free(victim); + free(victim); } } @@ -280,6 +280,7 @@ html_create_html_data(html_content *c, const http_parameter *params) c->base_url = nsurl_ref(content_get_url(&c->base)); c->base_target = NULL; c->aborted = false; + c->bctx = NULL; c->layout = NULL; c->background_colour = NS_TRANSPARENT; c->stylesheet_count = 0; @@ -313,7 +314,7 @@ html_create_html_data(html_content *c, const http_parameter *params) nerror = http_parameter_list_find_item(params, html_charset, &charset); if (nerror == NSERROR_OK) { - c->encoding = talloc_strdup(c, lwc_string_data(charset)); + c->encoding = strdup(lwc_string_data(charset)); lwc_string_unref(charset); @@ -341,7 +342,7 @@ html_create_html_data(html_content *c, const http_parameter *params) if ((c->parser == NULL) && (c->encoding != NULL)) { /* Ok, we don't support the declared encoding. Bailing out * isn't exactly user-friendly, so fall back to autodetect */ - talloc_free(c->encoding); + free(c->encoding); c->encoding = NULL; c->parser = dom_hubbub_parser_create(c->encoding, @@ -389,20 +390,20 @@ html_create(const content_handler *handler, html_content *html; nserror error; - html = talloc_zero(0, html_content); + html = calloc(1, sizeof(html_content)); if (html == NULL) return NSERROR_NOMEM; error = content__init(&html->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(html); + free(html); return error; } error = html_create_html_data(html, params); if (error != NSERROR_OK) { - talloc_free(html); + free(html); return error; } @@ -429,10 +430,16 @@ html_process_encoding_change(struct content *c, encoding = dom_hubbub_parser_get_encoding(html->parser, &html->encoding_source); + if (encoding == NULL) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + } + if (html->encoding != NULL) - talloc_free(html->encoding); + free(html->encoding); - html->encoding = talloc_strdup(c, encoding); + html->encoding = strdup(encoding); if (html->encoding == NULL) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); @@ -454,8 +461,8 @@ html_process_encoding_change(struct content *c, if (html->parser == NULL) { /* Ok, we don't support the declared encoding. Bailing out * isn't exactly user-friendly, so fall back to Windows-1252 */ - talloc_free(html->encoding); - html->encoding = talloc_strdup(c, "Windows-1252"); + free(html->encoding); + html->encoding = strdup("Windows-1252"); if (html->encoding == NULL) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); @@ -1515,8 +1522,8 @@ html_process_style_element(html_content *c, } /* Extend array */ - stylesheets = talloc_realloc(c, c->stylesheets, - struct html_stylesheet, *index + 1); + stylesheets = realloc(c->stylesheets, + sizeof(struct html_stylesheet) * (*index + 1)); if (stylesheets == NULL) goto no_memory; @@ -1527,7 +1534,7 @@ html_process_style_element(html_content *c, c->stylesheets[(*index)].data.internal = NULL; /* create stylesheet */ - sheet = talloc(c, struct content_css_data); + sheet = calloc(1, sizeof(struct content_css_data)); if (sheet == NULL) { c->stylesheet_count--; goto no_memory; @@ -1537,7 +1544,7 @@ html_process_style_element(html_content *c, nsurl_access(c->base_url), NULL, c->quirks, html_inline_style_done, c); if (error != NSERROR_OK) { - talloc_free(sheet); + free(sheet); c->stylesheet_count--; goto no_memory; } @@ -1548,7 +1555,7 @@ html_process_style_element(html_content *c, exc = dom_node_get_first_child(style, &child); if (exc != DOM_NO_ERR) { nscss_destroy_css_data(sheet); - talloc_free(sheet); + free(sheet); c->stylesheet_count--; goto no_memory; } @@ -1560,7 +1567,7 @@ html_process_style_element(html_content *c, if (exc != DOM_NO_ERR) { dom_node_unref(child); nscss_destroy_css_data(sheet); - talloc_free(sheet); + free(sheet); c->stylesheet_count--; goto no_memory; } @@ -1570,7 +1577,7 @@ html_process_style_element(html_content *c, dom_string_unref(data); dom_node_unref(child); nscss_destroy_css_data(sheet); - talloc_free(sheet); + free(sheet); c->stylesheet_count--; goto no_memory; } @@ -1581,7 +1588,7 @@ html_process_style_element(html_content *c, if (exc != DOM_NO_ERR) { dom_node_unref(child); nscss_destroy_css_data(sheet); - talloc_free(sheet); + free(sheet); c->stylesheet_count--; goto no_memory; } @@ -1599,7 +1606,7 @@ html_process_style_element(html_content *c, c->base.active--; LOG(("%d fetches active", c->base.active)); nscss_destroy_css_data(sheet); - talloc_free(sheet); + free(sheet); sheet = NULL; } @@ -1810,10 +1817,8 @@ html_process_stylesheet(dom_node *node, dom_string *name, void *vctx) LOG(("linked stylesheet %i '%s'", ctx->count, nsurl_access(joined))); /* start fetch */ - stylesheets = talloc_realloc(ctx->c, - ctx->c->stylesheets, - struct html_stylesheet, - ctx->count + 1); + stylesheets = realloc(ctx->c->stylesheets, + sizeof(struct html_stylesheet) * (ctx->count + 1)); if (stylesheets == NULL) { nsurl_unref(joined); goto no_memory; @@ -1882,10 +1887,10 @@ static bool html_find_stylesheets(html_content *c, dom_node *html) * stylesheet 1 is the quirks mode style sheet, * stylesheet 2 is the adblocking stylesheet, * stylesheet 3 is the user stylesheet */ - c->stylesheets = talloc_array(c, struct html_stylesheet, - STYLESHEET_START); - if (c->stylesheets == NULL) + c->stylesheets = calloc(STYLESHEET_START, sizeof(struct html_stylesheet)); + if (c->stylesheets == NULL) { goto html_find_stylesheets_no_memory; + } c->stylesheets[STYLESHEET_BASE].type = HTML_STYLESHEET_EXTERNAL; c->stylesheets[STYLESHEET_BASE].data.external = NULL; @@ -2030,10 +2035,16 @@ html_begin_conversion(html_content *htmlc) /* get encoding */ if (htmlc->encoding == NULL) { const char *encoding; + encoding = dom_hubbub_parser_get_encoding(htmlc->parser, &htmlc->encoding_source); + if (encoding == NULL) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data); + return false; + } - htmlc->encoding = talloc_strdup(&htmlc->base, encoding); + htmlc->encoding = strdup(encoding); if (htmlc->encoding == NULL) { msg_data.error = messages_get("NoMemory"); content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data); @@ -2219,7 +2230,7 @@ bool html_fetch_object(html_content *c, nsurl *url, struct box *box, child.charset = c->encoding; child.quirks = c->base.quirks; - object = talloc(c, struct content_html_object); + object = calloc(1, sizeof(struct content_html_object)); if (object == NULL) { return false; } @@ -2237,7 +2248,7 @@ bool html_fetch_object(html_content *c, nsurl *url, struct box *box, html_object_callback, object, &child, object->permitted_types, &object->content); if (error != NSERROR_OK) { - talloc_free(object); + free(object); return error != NSERROR_NOMEM; } @@ -2395,17 +2406,17 @@ static void html_destroy_frameset(struct content_html_frames *frameset) int i; if (frameset->name) { - talloc_free(frameset->name); + free(frameset->name); frameset->name = NULL; } if (frameset->url) { - talloc_free(frameset->url); + free(frameset->url); frameset->url = NULL; } if (frameset->children) { for (i = 0; i < (frameset->rows * frameset->cols); i++) { if (frameset->children[i].name) { - talloc_free(frameset->children[i].name); + free(frameset->children[i].name); frameset->children[i].name = NULL; } if (frameset->children[i].url) { @@ -2415,7 +2426,7 @@ static void html_destroy_frameset(struct content_html_frames *frameset) if (frameset->children[i].children) html_destroy_frameset(&frameset->children[i]); } - talloc_free(frameset->children); + free(frameset->children); frameset->children = NULL; } } @@ -2427,12 +2438,23 @@ static void html_destroy_iframe(struct content_html_iframe *iframe) while ((iframe = next) != NULL) { next = iframe->next; if (iframe->name) - talloc_free(iframe->name); + free(iframe->name); if (iframe->url) { nsurl_unref(iframe->url); iframe->url = NULL; } - talloc_free(iframe); + free(iframe); + } +} + + +static void html_free_layout(html_content *htmlc) +{ + if (htmlc->bctx != NULL) { + /* freeing talloc context should let the entire box + * set be destroyed + */ + talloc_free(htmlc->bctx); } } @@ -2481,7 +2503,7 @@ static void html_destroy(struct content *c) /* Free frameset */ if (html->frameset != NULL) { html_destroy_frameset(html->frameset); - talloc_free(html->frameset); + free(html->frameset); html->frameset = NULL; } @@ -2515,12 +2537,16 @@ static void html_destroy(struct content *c) html->stylesheets[i].data.internal); } } + free(html->stylesheets); /* Free scripts */ html_free_scripts(html); /* Free objects */ html_destroy_objects(html); + + /* free layout */ + html_free_layout(html); } diff --git a/render/html_internal.h b/render/html_internal.h index 9ff0f98cf..53021a15a 100644 --- a/render/html_internal.h +++ b/render/html_internal.h @@ -51,6 +51,8 @@ typedef struct html_content { /** Content has been aborted in the LOADING state */ bool aborted; + /** A talloc context purely for the render box tree */ + int *bctx; /** Box tree, or NULL. */ struct box *layout; /** Document background colour. */ diff --git a/render/layout.c b/render/layout.c index 0523cf9db..d0e3debe0 100644 --- a/render/layout.c +++ b/render/layout.c @@ -2162,7 +2162,7 @@ static bool layout_text_box_split(html_content *content, } /* Create clone of split_box, c2 */ - c2 = talloc_memdup(content, split_box, sizeof *c2); + c2 = talloc_memdup(content->bctx, split_box, sizeof *c2); if (!c2) return false; c2->flags |= CLONE; @@ -2172,7 +2172,7 @@ static bool layout_text_box_split(html_content *content, /* Inside a form text input / textarea, special case */ /* TODO: Move text inputs to core textarea widget and remove * this */ - c2->text = talloc_strndup(content, + c2->text = talloc_strndup(content->bctx, split_box->text + new_length + 1, split_box->length - (new_length + 1)); if (!c2->text) diff --git a/render/textplain.c b/render/textplain.c index 1877f32eb..6cf334fe2 100644 --- a/render/textplain.c +++ b/render/textplain.c @@ -47,7 +47,6 @@ #include "utils/http.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" #include "utils/utf8.h" @@ -212,14 +211,14 @@ nserror textplain_create(const content_handler *handler, nserror error; lwc_string *encoding; - text = talloc_zero(0, textplain_content); + text = calloc(1, sizeof(textplain_content)); if (text == NULL) return NSERROR_NOMEM; error = content__init(&text->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(text); + free(text); return error; } @@ -232,7 +231,7 @@ nserror textplain_create(const content_handler *handler, error = textplain_create_internal(text, encoding); if (error != NSERROR_OK) { lwc_string_unref(encoding); - talloc_free(text); + free(text); return error; } @@ -268,7 +267,7 @@ nserror textplain_create_internal(textplain_content *c, lwc_string *encoding) textplain_style.size = (nsoption_int(font_size) * FONT_SIZE_SCALE) / 10; - utf8_data = talloc_array(c, char, CHUNK); + utf8_data = malloc(CHUNK); if (utf8_data == NULL) goto no_memory; @@ -281,7 +280,7 @@ nserror textplain_create_internal(textplain_content *c, lwc_string *encoding) &stream); } if (error != PARSERUTILS_OK) { - talloc_free(utf8_data); + free(utf8_data); goto no_memory; } @@ -376,11 +375,11 @@ bool textplain_copy_utf8_data(textplain_content *c, { if (c->utf8_data_size + len >= c->utf8_data_allocated) { /* Compute next multiple of chunk above the required space */ - size_t allocated = (c->utf8_data_size + len + - CHUNK - 1) & ~(CHUNK - 1); - char *utf8_data = talloc_realloc(c, - c->utf8_data, - char, allocated); + size_t allocated; + char *utf8_data; + + allocated = (c->utf8_data_size + len + CHUNK - 1) & ~(CHUNK - 1); + utf8_data = realloc(c->utf8_data, allocated); if (utf8_data == NULL) return false; @@ -484,7 +483,7 @@ void textplain_reformat(struct content *c, int width, int height) if (!line) { text->physical_line = line = - talloc_array(c, struct textplain_line, 1024 + 3); + malloc(sizeof(struct textplain_line) * (1024 + 3)); if (!line) goto no_memory; } @@ -500,8 +499,9 @@ void textplain_reformat(struct content *c, int width, int height) if (term || next_col >= columns) { if (line_count % 1024 == 0) { - line1 = talloc_realloc(c, line, - struct textplain_line, line_count + 1024 + 3); + line1 = realloc(line, + sizeof(struct textplain_line) * + (line_count + 1024 + 3)); if (!line1) goto no_memory; text->physical_line = line = line1; @@ -558,8 +558,17 @@ void textplain_destroy(struct content *c) lwc_string_unref(text->encoding); - if (text->inputstream != NULL) + if (text->inputstream != NULL) { parserutils_inputstream_destroy(text->inputstream); + } + + if (text->physical_line != NULL) { + free(text->physical_line); + } + + if (text->utf8_data != NULL) { + free(text->utf8_data); + } } @@ -571,7 +580,7 @@ nserror textplain_clone(const struct content *old, struct content **newc) const char *data; unsigned long size; - text = talloc_zero(0, textplain_content); + text = calloc(1, sizeof(textplain_content)); if (text == NULL) return NSERROR_NOMEM; diff --git a/riscos/content-handlers/artworks.c b/riscos/content-handlers/artworks.c index b9c5f3378..66808d42a 100644 --- a/riscos/content-handlers/artworks.c +++ b/riscos/content-handlers/artworks.c @@ -39,7 +39,6 @@ #include "riscos/wimputils.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" #define AWRender_FileInitAddress 0x46080 @@ -140,14 +139,14 @@ nserror artworks_create(const content_handler *handler, artworks_content *aw; nserror error; - aw = talloc_zero(0, artworks_content); + aw = calloc(1, sizeof(artworks_content)); if (aw == NULL) return NSERROR_NOMEM; error = content__init(&aw->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(aw); + free(aw); return error; } @@ -406,7 +405,7 @@ nserror artworks_clone(const struct content *old, struct content **newc) artworks_content *aw; nserror error; - aw = talloc_zero(0, artworks_content); + aw = calloc(1, sizeof(artworks_content)); if (aw == NULL) return NSERROR_NOMEM; diff --git a/riscos/content-handlers/draw.c b/riscos/content-handlers/draw.c index 0d8c86914..d18d580cd 100644 --- a/riscos/content-handlers/draw.c +++ b/riscos/content-handlers/draw.c @@ -35,7 +35,6 @@ #include "riscos/gui.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" typedef struct draw_content { @@ -82,14 +81,14 @@ nserror draw_create(const content_handler *handler, draw_content *draw; nserror error; - draw = talloc_zero(0, draw_content); + draw = calloc(1, sizeof(draw_content)); if (draw == NULL) return NSERROR_NOMEM; error = content__init(&draw->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(draw); + free(draw); return error; } @@ -218,7 +217,7 @@ nserror draw_clone(const struct content *old, struct content **newc) draw_content *draw; nserror error; - draw = talloc_zero(0, draw_content); + draw = calloc(1, sizeof(draw_content)); if (draw == NULL) return NSERROR_NOMEM; diff --git a/riscos/content-handlers/sprite.c b/riscos/content-handlers/sprite.c index 7b6045cb9..9a70ebe75 100644 --- a/riscos/content-handlers/sprite.c +++ b/riscos/content-handlers/sprite.c @@ -35,7 +35,6 @@ #include "utils/config.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" #ifdef WITH_SPRITE @@ -81,14 +80,14 @@ nserror sprite_create(const content_handler *handler, sprite_content *sprite; nserror error; - sprite = talloc_zero(0, sprite_content); + sprite = calloc(1, sizeof(sprite_content)); if (sprite == NULL) return NSERROR_NOMEM; error = content__init(&sprite->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(sprite); + free(sprite); return error; } @@ -191,7 +190,7 @@ nserror sprite_clone(const struct content *old, struct content **newc) sprite_content *sprite; nserror error; - sprite = talloc_zero(0, sprite_content); + sprite = calloc(1, sizeof(sprite_content)); if (sprite == NULL) return NSERROR_NOMEM; |