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

ASAN reports memleaks for tests/bug330.phpt #533

Open
mikhainin opened this issue Mar 9, 2023 · 0 comments
Open

ASAN reports memleaks for tests/bug330.phpt #533

mikhainin opened this issue Mar 9, 2023 · 0 comments
Labels

Comments

@mikhainin
Copy link

mikhainin commented Mar 9, 2023

Description

The following code:

<?php
$conf = new Conf();
$conf->set('group.id','test');
$consumer = new KafkaConsumer($conf);
$topic = $consumer->newTopic('test');
unset($topic);
var_dump(isset($topic));

When built with ASAN and run like this:

ZEND_DONT_UNLOAD_MODULES=1 ./tests/bug330.sh

Resulted in this output:

    #0 0x7fc596191db0 in strdup (/lib64/libasan.so.5+0x3bdb0)
    #1 0x7fc59080c4ee in rd_strdup /home/mgalanin/php-build/librdkafka-2.0.2/src/rd.h:156
    #2 0x7fc59080fe06 in rd_kafka_anyconf_set_prop0 /home/mgalanin/php-build/librdkafka-2.0.2/src/rdkafka_conf.c:1725
    #3 0x7fc59081237f in rd_kafka_defaultconf_set /home/mgalanin/php-build/librdkafka-2.0.2/src/rdkafka_conf.c:2171
    #4 0x7fc59081248e in rd_kafka_topic_conf_new /home/mgalanin/php-build/librdkafka-2.0.2/src/rdkafka_conf.c:2191
    #5 0x7fc590802a93 in rd_kafka_topic_new0 /home/mgalanin/php-build/librdkafka-2.0.2/src/rdkafka_topic.c:303
    #6 0x7fc590804450 in rd_kafka_topic_new /home/mgalanin/php-build/librdkafka-2.0.2/src/rdkafka_topic.c:510
    #7 0x7fc590ff2da7 in zim_RdKafka_KafkaConsumer_newTopic /home/mgalanin/php-build/github.com-tony2001-php-rdkafka/kafka_consumer.c:561
    #8 0xd3438d in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER /home/mgalanin/php-build/php-sources/Zend/zend_vm_execute.h:1863
    #9 0xe7687e in execute_ex /home/mgalanin/php-build/php-sources/Zend/zend_vm_execute.h:55195
    #10 0xe83e40 in zend_execute /home/mgalanin/php-build/php-sources/Zend/zend_vm_execute.h:59523
    #11 0xca0a4d in zend_execute_scripts /home/mgalanin/php-build/php-sources/Zend/zend.c:1826
    #12 0xb309dc in php_execute_script /home/mgalanin/php-build/php-sources/main/main.c:2568
    #13 0xf1b6ff in do_cli /home/mgalanin/php-build/php-sources/sapi/cli/php_cli.c:949
    #14 0xf1d9dc in main /home/mgalanin/php-build/php-sources/sapi/cli/php_cli.c:1341
    #15 0x7fc594c90d84 in __libc_start_main (/lib64/libc.so.6+0x3ad84)

From what I can see, PHP_METHOD(RdKafka_KafkaConsumer, newTopic) calls rd_kafka_topic_new() but the result is never gets freed as kafka_topic_free() only considers that it can be referred from a kafka_object

I was able to fix the problem like this:

diff --git a/topic.c b/topic.c
index f1c0f7f..08b20d2 100644
--- a/topic.c
+++ b/topic.c
@@ -57,6 +57,9 @@ static void kafka_topic_free(zend_object *object) /* {{{ */
         if (kafka_intern) {
             zend_hash_index_del(&kafka_intern->topics, (zend_ulong)intern);
         }
+    } else if (intern->rkt) {
+        // the class created via KafkaConsumer::newTopic()
+        rd_kafka_topic_destroy(intern->rkt);
     }
 
     zend_object_std_dtor(&intern->std);

but not sure if it's the right way

php-rdkafka Version

6.0.3 (latest revision from "6.x" branch)

librdkafka Version

2.0.2

PHP Version

8.0.28

Operating System

No response

Kafka Version

No response

@mikhainin mikhainin added the bug label Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant