From c84dfd7e182d48c30990144f24001060febc8066 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 10 May 2015 17:27:55 +0200 Subject: [PATCH] mem_free_if where aplicable. Initialised memory in encoding/* --- src/bfu/listmenu.c | 2 +- src/document/html/parser/forms.c | 2 +- src/document/html/parser/stack.c | 2 +- src/document/html/tables.c | 2 +- src/encoding/bzip2.c | 3 ++- src/encoding/deflate.c | 2 +- src/encoding/lzma.c | 3 ++- src/protocol/bittorrent/bittorrent.c | 2 +- src/scripting/smjs/action_object.c | 2 +- 9 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/bfu/listmenu.c b/src/bfu/listmenu.c index ecf95677..07350f5c 100644 --- a/src/bfu/listmenu.c +++ b/src/bfu/listmenu.c @@ -90,7 +90,7 @@ new_menu_item(struct list_menu *menu, unsigned char *name, int data, int fullnam } if (!stack || !new_menu_item) { - if (new_menu_item) mem_free(new_menu_item); + mem_free_if(new_menu_item); mem_free(name); return; } diff --git a/src/document/html/parser/forms.c b/src/document/html/parser/forms.c index d40a569a..ad938e99 100644 --- a/src/document/html/parser/forms.c +++ b/src/document/html/parser/forms.c @@ -195,7 +195,7 @@ html_input_format(struct html_context *html_context, unsigned char *a, html_stack_dup(html_context, ELEMENT_KILLABLE); html_focusable(html_context, a); format.form = fc; - if (format.title) mem_free(format.title); + mem_free_if(format.title); format.title = get_attr_val(a, "title", html_context->doc_cp); switch (fc->type) { case FC_TEXT: diff --git a/src/document/html/parser/stack.c b/src/document/html/parser/stack.c index 6d63abfe..05899490 100644 --- a/src/document/html/parser/stack.c +++ b/src/document/html/parser/stack.c @@ -98,7 +98,7 @@ kill_html_stack_item(struct html_context *html_context, struct html_element *e) add_to_string_list(&html_context->part->document->onload_snippets, onload, -1); } - if (onload) mem_free(onload); + mem_free_if(onload); #endif mem_free_if(e->attr.link); diff --git a/src/document/html/tables.c b/src/document/html/tables.c index cc4b9c89..37119dd0 100644 --- a/src/document/html/tables.c +++ b/src/document/html/tables.c @@ -899,7 +899,7 @@ draw_table_cell(struct table *table, int col, int row, int x, int y, done_html_parser_state(html_context, state); - if (part) mem_free(part); + mem_free_if(part); } static void diff --git a/src/encoding/bzip2.c b/src/encoding/bzip2.c index 5cc21f24..8fcfbd7b 100644 --- a/src/encoding/bzip2.c +++ b/src/encoding/bzip2.c @@ -67,6 +67,7 @@ bzip2_open(struct stream_encoded *stream, int fd) copy_struct(&data->fbz_stream, &null_bz_stream); data->fdread = fd; data->last_read = 0; + data->after_end = 0; err = BZ2_bzDecompressInit(&data->fbz_stream, 0, 0); if (err != BZ_OK) { @@ -189,7 +190,7 @@ bzip2_decode_buffer(struct stream_encoded *st, unsigned char *data, int len, int *new_len = stream->total_out_lo32; return buffer; } else { - if (buffer) mem_free(buffer); + mem_free_if(buffer); return NULL; } } diff --git a/src/encoding/deflate.c b/src/encoding/deflate.c index 27d5b839..29401355 100644 --- a/src/encoding/deflate.c +++ b/src/encoding/deflate.c @@ -214,7 +214,7 @@ deflate_decode_buffer(struct stream_encoded *st, int window_size, unsigned char *new_len = stream->total_out; return buffer; } else { - if (buffer) mem_free(buffer); + mem_free_if(buffer); return NULL; } } diff --git a/src/encoding/lzma.c b/src/encoding/lzma.c index 9b656920..8ae452b3 100644 --- a/src/encoding/lzma.c +++ b/src/encoding/lzma.c @@ -46,6 +46,7 @@ lzma_open(struct stream_encoded *stream, int fd) memset(&data->flzma_stream, 0, sizeof(data->flzma_stream)); data->fdread = fd; data->last_read = 0; + data->after_end = 0; err = lzma_auto_decoder(&data->flzma_stream, ELINKS_LZMA_MEMORY_LIMIT, 0); if (err != LZMA_OK) { @@ -153,7 +154,7 @@ lzma_decode_buffer(struct stream_encoded *st, unsigned char *data, int len, int *new_len = stream->total_out; return buffer; } else { - if (buffer) mem_free(buffer); + mem_free_if(buffer); return NULL; } } diff --git a/src/protocol/bittorrent/bittorrent.c b/src/protocol/bittorrent/bittorrent.c index 60dfca37..6bc8b6e6 100644 --- a/src/protocol/bittorrent/bittorrent.c +++ b/src/protocol/bittorrent/bittorrent.c @@ -281,7 +281,7 @@ add_bittorrent_selection(struct uri *uri, int *selection, size_t size) int *duplicate; duplicate = get_bittorrent_selection(uri, size); - if (duplicate) mem_free(duplicate); + mem_free_if(duplicate); info = mem_calloc(1, sizeof(*info)); if (!info) return; diff --git a/src/scripting/smjs/action_object.c b/src/scripting/smjs/action_object.c index acc6110e..113d132a 100644 --- a/src/scripting/smjs/action_object.c +++ b/src/scripting/smjs/action_object.c @@ -37,7 +37,7 @@ smjs_action_fn_finalize(JSContext *ctx, JSObject *obj) hop = JS_GetInstancePrivate(ctx, obj, (JSClass *) &action_fn_class, NULL); - if (hop) mem_free(hop); + mem_free_if(hop); } /* @action_fn_class.call */