Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak readline #17154

Open
YuanchengJiang opened this issue Dec 14, 2024 · 1 comment · May be fixed by #17155
Open

memory leak readline #17154

YuanchengJiang opened this issue Dec 14, 2024 · 1 comment · May be fixed by #17155

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
readline_info('line_buffer', 'abcdef');
readline_write_history($name);

Resulted in this output:

==3505130==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7 byte(s) in 1 object(s) allocated from:
    #0 0x66c494 in strdup (/home/phpfuzz/WorkSpace/flowfusion/php-src/sapi/cli/php+0x66c494)
    #1 0x23683f1 in zif_readline_info /home/phpfuzz/WorkSpace/flowfusion/php-src/ext/readline/readline.c:199:17
    #2 0x4484b19 in ZEND_DO_ICALL_SPEC_RETVAL_UNUSED_HANDLER /home/phpfuzz/WorkSpace/flowfusion/php-src/Zend/zend_vm_execute.h:1299:2
    #3 0x3f7c237 in execute_ex /home/phpfuzz/WorkSpace/flowfusion/php-src/Zend/zend_vm_execute.h:58595:7
    #4 0x3f7e4bc in zend_execute /home/phpfuzz/WorkSpace/flowfusion/php-src/Zend/zend_vm_execute.h:64247:2
    #5 0x4d151c9 in zend_execute_script /home/phpfuzz/WorkSpace/flowfusion/php-src/Zend/zend.c:1934:3
    #6 0x35298da in php_execute_script_ex /home/phpfuzz/WorkSpace/flowfusion/php-src/main/main.c:2577:13
    #7 0x352aa18 in php_execute_script /home/phpfuzz/WorkSpace/flowfusion/php-src/main/main.c:2617:9
    #8 0x4d294da in do_cli /home/phpfuzz/WorkSpace/flowfusion/php-src/sapi/cli/php_cli.c:938:5
    #9 0x4d239bf in main /home/phpfuzz/WorkSpace/flowfusion/php-src/sapi/cli/php_cli.c:1313:18
    #10 0x7fa51f4fad8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16

SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).

PHP Version

nightly

Operating System

ubuntu 22.04

@devnexen
Copy link
Member

definitively the global rl_line_buffer address is reassigned when calling write_history thus previous value is lost. Will look into it.

@devnexen devnexen self-assigned this Dec 14, 2024
devnexen added a commit to devnexen/php-src that referenced this issue Dec 14, 2024
…it).

When there is no history, any subsequent history api call initialising
it will call rl_initialise() thus we lose the previous value in the
process.
At module init time, we also call using_history() like with readline.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants