JSValueConst *argv, int raw)
{
int rc, level, mem_level, strategy, window_bits;
- size_t chunk_size;
+ u_char *dictionary_copy;
+ size_t chunk_size, dictionary_length;
uint64_t chunk_size_value;
JSValue ret, options;
z_stream stream;
NJS_CHB_CTX_INIT(&chain, ctx);
dictionary.start = NULL;
dictionary.length = 0;
+ dictionary_copy = NULL;
+ dictionary_length = 0;
stream.opaque = NULL;
options = argv[1];
if (rc != 0) {
return JS_EXCEPTION;
}
+
+ dictionary_copy = js_malloc(ctx, dictionary.length);
+ if (dictionary_copy == NULL && dictionary.length != 0) {
+ qjs_bytes_free(ctx, &dictionary);
+ return JS_EXCEPTION;
+ }
+
+ memcpy(dictionary_copy, dictionary.start, dictionary.length);
+ dictionary_length = dictionary.length;
+ qjs_bytes_free(ctx, &dictionary);
+ dictionary.start = NULL;
}
}
rc = qjs_to_bytes(ctx, &bytes, argv[0]);
if (rc != 0) {
+ js_free(ctx, dictionary_copy);
return JS_EXCEPTION;
}
goto fail;
}
- if (dictionary.start != NULL) {
- rc = deflateSetDictionary(&stream, dictionary.start, dictionary.length);
+ if (dictionary_copy != NULL) {
+ rc = deflateSetDictionary(&stream, dictionary_copy, dictionary_length);
if (rc != Z_OK) {
JS_ThrowInternalError(ctx, "deflateSetDictionary() failed");
goto fail;
qjs_bytes_free(ctx, &bytes);
- if (dictionary.start != NULL) {
- qjs_bytes_free(ctx, &dictionary);
- }
+ js_free(ctx, dictionary_copy);
ret = qjs_buffer_chb_alloc(ctx, &chain);
qjs_bytes_free(ctx, &bytes);
- if (dictionary.start != NULL) {
- qjs_bytes_free(ctx, &dictionary);
- }
+ js_free(ctx, dictionary_copy);
if (stream.opaque != NULL) {
deflateEnd(&stream);
JSValueConst *argv, int raw)
{
int rc, window_bits;
- size_t chunk_size;
+ u_char *dictionary_copy;
+ size_t chunk_size, dictionary_length;
uint64_t chunk_size_value;
JSValue ret, options;
z_stream stream;
NJS_CHB_CTX_INIT(&chain, ctx);
dictionary.start = NULL;
dictionary.length = 0;
+ dictionary_copy = NULL;
+ dictionary_length = 0;
stream.opaque = NULL;
options = argv[1];
if (rc != 0) {
return JS_EXCEPTION;
}
+
+ dictionary_copy = js_malloc(ctx, dictionary.length);
+ if (dictionary_copy == NULL && dictionary.length != 0) {
+ qjs_bytes_free(ctx, &dictionary);
+ return JS_EXCEPTION;
+ }
+
+ memcpy(dictionary_copy, dictionary.start, dictionary.length);
+ dictionary_length = dictionary.length;
+ qjs_bytes_free(ctx, &dictionary);
+ dictionary.start = NULL;
}
}
rc = qjs_to_bytes(ctx, &bytes, argv[0]);
if (rc != 0) {
+ js_free(ctx, dictionary_copy);
return JS_EXCEPTION;
}
goto fail;
}
- if (dictionary.start != NULL) {
- rc = inflateSetDictionary(&stream, dictionary.start, dictionary.length);
+ if (dictionary_copy != NULL) {
+ rc = inflateSetDictionary(&stream, dictionary_copy, dictionary_length);
if (rc != Z_OK) {
JS_ThrowInternalError(ctx, "inflateSetDictionary() failed");
goto fail;
qjs_bytes_free(ctx, &bytes);
- if (dictionary.start != NULL) {
- qjs_bytes_free(ctx, &dictionary);
- }
+ js_free(ctx, dictionary_copy);
ret = qjs_buffer_chb_alloc(ctx, &chain);
qjs_bytes_free(ctx, &bytes);
+ js_free(ctx, dictionary_copy);
+
if (dictionary.start != NULL) {
qjs_bytes_free(ctx, &dictionary);
}