diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2008-11-09 12:42:11 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2008-11-09 12:42:11 +0000 |
commit | fc80fc27bf89226b96bdc6ddbe1847c3908ea6a2 (patch) | |
tree | 9337ca9362c57cabff42e547b53e82c9f54dde60 /src/input/filter.c | |
parent | e53a5011237467c73c72b338570e4a455d2d1ef6 (diff) | |
download | libparserutils-fc80fc27bf89226b96bdc6ddbe1847c3908ea6a2.tar.gz libparserutils-fc80fc27bf89226b96bdc6ddbe1847c3908ea6a2.tar.bz2 |
Fix double free of filter read codec when resetting to an unsupported encoding.
svn path=/trunk/libparserutils/; revision=5657
Diffstat (limited to 'src/input/filter.c')
-rw-r--r-- | src/input/filter.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/input/filter.c b/src/input/filter.c index 716fbf6..d6457f3 100644 --- a/src/input/filter.c +++ b/src/input/filter.c @@ -100,8 +100,10 @@ parserutils_error parserutils_filter_create(const char *int_enc, error = parserutils_charset_codec_create(int_enc, alloc, pw, &f->write_codec); if (error != PARSERUTILS_OK) { - if (f->read_codec != NULL) + if (f->read_codec != NULL) { parserutils_charset_codec_destroy(f->read_codec); + f->read_codec = NULL; + } f->alloc(f, 0, pw); return error; } @@ -124,14 +126,20 @@ parserutils_error parserutils_filter_destroy(parserutils_filter *input) return PARSERUTILS_BADPARM; #ifdef WITH_ICONV_FILTER - if (input->cd != (iconv_t) -1) + if (input->cd != (iconv_t) -1) { iconv_close(input->cd); + input->cd = (iconv_t) -1; + } #else - if (input->read_codec != NULL) + if (input->read_codec != NULL) { parserutils_charset_codec_destroy(input->read_codec); + input->read_codec = NULL; + } - if (input->write_codec != NULL) + if (input->write_codec != NULL) { parserutils_charset_codec_destroy(input->write_codec); + input->write_codec = NULL; + } #endif input->alloc(input, 0, input->pw); @@ -383,16 +391,20 @@ parserutils_error filter_set_encoding(parserutils_filter *input, old_enc = "UTF-8"; #ifdef WITH_ICONV_FILTER - if (input->cd != (iconv_t) -1) + if (input->cd != (iconv_t) -1) { iconv_close(input->cd); + input->cd = (iconv_t) -1; + } input->cd = iconv_open( parserutils_charset_mibenum_to_name(input->int_enc), enc); if (input->cd == (iconv_t) -1) return PARSERUTILS_NOMEM; #else - if (input->read_codec != NULL) + if (input->read_codec != NULL) { parserutils_charset_codec_destroy(input->read_codec); + input->read_codec = NULL; + } error = parserutils_charset_codec_create(enc, input->alloc, input->pw, &input->read_codec); @@ -403,4 +415,5 @@ parserutils_error filter_set_encoding(parserutils_filter *input, input->settings.encoding = mibenum; return PARSERUTILS_OK; + } |