Skip to content

fix: resolve memory leak of input buffer in REPL mode for bitwise expressions - #45

Merged
jarun merged 1 commit into
jarun:masterfrom
pro-laxmi:fix/repl-bitwise-memory-leak
Nov 25, 2026
Merged

jarun merged 1 commit into
jarun:masterfrom
pro-laxmi:fix/repl-bitwise-memory-leak

Conversation

@pro-laxmi

Copy link
Copy Markdown
Contributor

Summary of Changes

In interactive REPL mode, evaluating bitwise expressions leaked the input buffer allocated by getinput() because free(ptr) was bypassed when eval_bitwise_expr(...) == 0.

Root Cause

In src/bcal.c:

if (has_bitwise_ops(tmp)) {
    if (eval_bitwise_expr(tmp, lastres.p, UINT_BUF_LEN) == 0) {
        continue; // ptr is never freed!
    }
    free(ptr);
    continue;
}

Fix

Consistently invoke free(ptr) before continue:

if (has_bitwise_ops(tmp)) {
    eval_bitwise_expr(tmp, lastres.p, UINT_BUF_LEN);
    free(ptr);
    continue;
}

Verification & Testing

  • Validated in REPL mode with various bitwise operations (0x10 & 0x01, 0x2 << 2).
  • Compiled with -Wall -Wextra -Werror cleanly.

@jarun
jarun merged commit 926a0dd into jarun:master Nov 25, 2026
2 checks passed
@jarun

jarun commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants