Skip to content

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

Open
pro-laxmi wants to merge 1 commit into
jarun:masterfrom
pro-laxmi:fix/repl-bitwise-memory-leak
Open

pro-laxmi wants to merge 1 commit into
jarun:masterfrom
pro-laxmi:fix/repl-bitwise-memory-leak

Conversation

@pro-laxmi

Copy link
Copy Markdown

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.

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.

1 participant