mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
utf8_to_jsstring: Don't free mem handed over to JS
In utf8_to_jsstring, do not free the string that is passed to JS_NewUCString if the latter is successful; if it is, SpiderMonkey handles the memory from then on. Use libc routines instead of ELinks's routines to allocate and free the string so that ELinks's memory debugging code does not try to keep track of it after it has been handed to SpiderMonkey. This commit fixes a bug introdued in 97d72d15a0dbde3e8c8c51eb139f270874e37fda.
This commit is contained in:
parent
9b9f5d9973
commit
f11b2a8f97
@ -4,6 +4,8 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
#include "config/home.h"
|
||||
@ -205,7 +207,7 @@ utf8_to_jsstring(JSContext *ctx, const unsigned char *str, int length)
|
||||
utf16_alloc = in_bytes;
|
||||
/* Don't use fmem_alloc here because long strings could
|
||||
* exhaust the stack. */
|
||||
utf16 = mem_alloc(utf16_alloc * sizeof(jschar));
|
||||
utf16 = malloc(utf16_alloc * sizeof(jschar));
|
||||
if (utf16 == NULL) {
|
||||
JS_ReportOutOfMemory(ctx);
|
||||
return NULL;
|
||||
@ -223,18 +225,19 @@ utf8_to_jsstring(JSContext *ctx, const unsigned char *str, int length)
|
||||
|
||||
if (needs_utf16_surrogates(unicode)) {
|
||||
assert(utf16_alloc - utf16_used >= 2);
|
||||
if_assert_failed { mem_free(utf16); return NULL; }
|
||||
if_assert_failed { free(utf16); return NULL; }
|
||||
utf16[utf16_used++] = get_utf16_high_surrogate(unicode);
|
||||
utf16[utf16_used++] = get_utf16_low_surrogate(unicode);
|
||||
} else {
|
||||
assert(utf16_alloc - utf16_used >= 1);
|
||||
if_assert_failed { mem_free(utf16); return NULL; }
|
||||
if_assert_failed { free(utf16); return NULL; }
|
||||
utf16[utf16_used++] = unicode;
|
||||
}
|
||||
}
|
||||
|
||||
jsstr = JS_NewUCString(ctx, utf16, utf16_used);
|
||||
mem_free(utf16);
|
||||
if (jsstr == NULL) free(utf16);
|
||||
|
||||
return jsstr;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user