summaryrefslogtreecommitdiff
path: root/yjit_core.c
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2021-12-08 12:24:37 -0500
committerAlan Wu <XrXr@users.noreply.github.com>2021-12-08 16:59:52 -0500
commit82bb9cedd3fb41fd78d612153c35fdb8c5344d5a (patch)
tree06914a3fddbaffa8e436a0a31b4c8df2541f4a51 /yjit_core.c
parentc47e821b8928b1a8755dc8693ffce57342c10868 (diff)
YJIT: Fix leak in compilation loop
Previously, when there are too many blocks in a batch, the last block in the batch is not tracked in the array of batches and not freed.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5229
Diffstat (limited to 'yjit_core.c')
-rw-r--r--yjit_core.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/yjit_core.c b/yjit_core.c
index b226f8bd34..02f629d9ce 100644
--- a/yjit_core.c
+++ b/yjit_core.c
@@ -747,15 +747,14 @@ gen_block_version(blockid_t blockid, const ctx_t *start_ctx, rb_execution_contex
// Generate code for the first block
block = gen_single_block(blockid, start_ctx, ec);
- batch_success = block && compiled_count < MAX_PER_BATCH;
-
- if (batch_success) {
+ if (block) {
// Track the block
add_block_version(block);
batch[compiled_count] = block;
compiled_count++;
}
+ batch_success = block;
// For each successor block to compile
while (batch_success) {
@@ -780,8 +779,12 @@ gen_block_version(blockid_t blockid, const ctx_t *start_ctx, rb_execution_contex
// Generate code for the current block using context from the last branch.
blockid_t requested_id = last_branch->targets[0];
const ctx_t *requested_ctx = &last_branch->target_ctxs[0];
- block = gen_single_block(requested_id, requested_ctx, ec);
- batch_success = block && compiled_count < MAX_PER_BATCH;
+
+ batch_success = compiled_count < MAX_PER_BATCH;
+ if (batch_success) {
+ block = gen_single_block(requested_id, requested_ctx, ec);
+ batch_success = block;
+ }
// If the batch failed, stop
if (!batch_success) {