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

Release memory in Imagick::getConfigureOptions() #600

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mikhainin
Copy link

A few memleaks reported by ASAN.

it seems like MagickQueryConfigureOptions() returns not-constant memory and we will have to clean that up

$ ZEND_DONT_UNLOAD_MODULES=1 ./tests/254_getConfigureOptions.sh
Ok
==24023==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 182504 byte(s) in 44 object(s) allocated from:
    #0 0x7f53e933fbb8 in __interceptor_malloc (/lib64/libasan.so.5+0xefbb8)
    #1 0x7f53e3b2c436 in AcquireString MagickCore/string.c:107

Direct leak of 688 byte(s) in 2 object(s) allocated from:
    #0 0x7f53e933fbb8 in __interceptor_malloc (/lib64/libasan.so.5+0xefbb8)
    #1 0x7f53e39e1c89 in GetConfigureList MagickCore/configure.c:554

Indirect leak of 480 byte(s) in 44 object(s) allocated from:
    #0 0x7f53e933fbb8 in __interceptor_malloc (/lib64/libasan.so.5+0xefbb8)
    #1 0x7f53e3b2cb93 in ConstantString MagickCore/string.c:691

SUMMARY: AddressSanitizer: 183672 byte(s) leaked in 90 allocation(s).

@Danack
Copy link
Collaborator

Danack commented Jun 25, 2024

Hi,

I appear to have already committed these in 2b0ecc4 and d521b3c but forgot to say anything here.

If you're able to, please can you give me (or point me to) some instruction to how to use ASAN so that I can avoid these types of errors in the future?

@mikhainin
Copy link
Author

Ah, ASAN is actually easy: https://github.com/google/sanitizers/wiki/AddressSanitizer
You just need to build all the participating components (PHP, the extenstion, and ideally ImageMagick as well) with CFLAGS="-fsanitize=address -g -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address". I tend to add -O0 -ggdb3 as well.

PHP - I make a separate build (working at Bumble we had a build scenario that was building all the required extensions and other components, although I don't work there anymore):

git clone https://github.com/php/php-src.git
cd php-src
./buildconf
./configure --enable-address-sanitizer --prefix=/opt/php-asan
make -j40
make install

The extension

git clone https://github.com/Imagick/imagick.git
cd imagick
/opt/php-asan/bin/phpize
./configure --with-php-config=/opt/php-asan/bin/php-config CFLAGS="-fsanitize=address -g" LDFLAGS="-fsanitize=address"
make -j10

And then run the tests (or whatever you want).

It's better to use ZEND_DONT_UNLOAD_MODULES=1: ASAN dumps stack-trace on termination, if PHP has unloaded the module, the trace will be not readable.

ZEND_DONT_UNLOAD_MODULES=1 TESTS='-j10' make test

@mikhainin
Copy link
Author

Probably, the main problem atm is that it doesn't work on ARMs (newest macbooks)

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