From 81810d58f84d383deadef37f63f453fe58be3ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Lang=C3=B3?= Date: Wed, 19 Sep 2018 20:47:16 +0200 Subject: [PATCH] Fix memory leak in the snapshot creation. (#2533) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bytecode must be freed when the source is parsed succesfully, but the snapshot generating fails for some other reason. JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com --- jerry-core/api/jerry-snapshot.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jerry-core/api/jerry-snapshot.c b/jerry-core/api/jerry-snapshot.c index 92546a5bd..d4ee42ff2 100644 --- a/jerry-core/api/jerry-snapshot.c +++ b/jerry-core/api/jerry-snapshot.c @@ -768,6 +768,8 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr return ecma_create_error_reference (JERRY_CONTEXT (error_value), true); } + JERRY_ASSERT (bytecode_data_p != NULL); + if (generate_snapshot_opts & JERRY_SNAPSHOT_SAVE_STATIC) { static_snapshot_add_compiled_code (bytecode_data_p, (uint8_t *) buffer_p, buffer_size, &globals); @@ -779,6 +781,7 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr if (!ecma_is_value_empty (globals.snapshot_error)) { + ecma_bytecode_deref (bytecode_data_p); return globals.snapshot_error; } @@ -808,6 +811,7 @@ jerry_generate_snapshot_with_args (const jerry_char_t *resource_name_p, /**< scr { JERRY_ASSERT (lit_map_p == NULL); const char * const error_message_p = "Cannot allocate memory for literals."; + ecma_bytecode_deref (bytecode_data_p); return jerry_create_error (JERRY_ERROR_COMMON, (const jerry_char_t *) error_message_p); }