# could need some help with memory leaks

- Thread: https://externals.io/message/28472
- Original archive: https://news-web.php.net/php.internals/28472
- Started by Oliver Block on 2007-03-19T23:15:32+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #28472 — Oliver Block — 2007-03-19T23:15:32+00:00

URL: https://externals.io/message/28472#28472

Hello,

I rewrote imap_mail_compose() and (almost) everything works fine, but I can't
get rid of some memory leaks.

In order to compose nested mutlipart messages I created a hash_table

[Mon Mar 19 23:44:36 2007]  Script:  '/root/compose_multipart.php'
/usr/local/src/php-5.2.1/Zend/zend_execute.c(1062) :  Freeing 0x40835DA4 (32
bytes), script=/root/compose_multipart.php
/usr/local/src/php-5.2.1/Zend/zend_alloc.c(1917) : Actual location (location
was relayed)
[Mon Mar 19 23:44:36 2007]  Script:  '/root/compose_multipart.php'
/usr/local/src/php-5.2.1/Zend/zend_execute.c(1006) :  Freeing 0x40835DF4 (35
bytes), script=/root/compose_multipart.php
/usr/local/src/php-5.2.1/Zend/zend_hash.c(388) : Actual location (location was
relayed)
Last leak repeated 1 time
[Mon Mar 19 23:44:36 2007]  Script:  '/root/compose_multipart.php'
/usr/local/src/php-5.2.1/ext/imap/php_imap.c(3340) :  Freeing 0x40836E4C (44
bytes), script=/root/compose_multipart.php
/usr/local/src/php-5.2.1/Zend/zend_API.c(819) : Actual location (location was
relayed)
Last leak repeated 1 time
=== Total 5 memory leaks detected ===

That's what I found out so far:
			
When the function that is called in the script (/root/compose_multipart.php) is
accessed, the address  0x40835DA4 has the value 0x40835DF4 at the very
beginning. The address 0x40835DF4 has 0x00000000.

Can anybody help me to understand the output?


Regards,

Oliver

---

## #28473 — Stanislav Malyshev — 2007-03-19T23:21:48+00:00

URL: https://externals.io/message/28472#28473 · In reply to: #28472

Oliver Block wrote:
> Hello,
> 
> I rewrote imap_mail_compose() and (almost) everything works fine, but I can't
> get rid of some memory leaks.
> 
> In order to compose nested mutlipart messages I created a hash_table
> 
> [Mon Mar 19 23:44:36 2007]  Script:  '/root/compose_multipart.php'
> /usr/local/src/php-5.2.1/Zend/zend_execute.c(1062) :  Freeing 0x40835DA4 (32
> bytes), script=/root/compose_multipart.php
> /usr/local/src/php-5.2.1/Zend/zend_alloc.c(1917) : Actual location (location
> was relayed)
> [Mon Mar 19 23:44:36 2007]  Script:  '/root/compose_multipart.php'
> /usr/local/src/php-5.2.1/Zend/zend_execute.c(1006) :  Freeing 0x40835DF4 (35
> bytes), script=/root/compose_multipart.php
> /usr/local/src/php-5.2.1/Zend/zend_hash.c(388) : Actual location (location was
> relayed)
> Last leak repeated 1 time
> [Mon Mar 19 23:44:36 2007]  Script:  '/root/compose_multipart.php'
> /usr/local/src/php-5.2.1/ext/imap/php_imap.c(3340) :  Freeing 0x40836E4C (44
> bytes), script=/root/compose_multipart.php
> /usr/local/src/php-5.2.1/Zend/zend_API.c(819) : Actual location (location was
> relayed)
> Last leak repeated 1 time
> === Total 5 memory leaks detected ===
> 
> That's what I found out so far:
> 			
> When the function that is called in the script (/root/compose_multipart.php) is
> accessed, the address  0x40835DA4 has the value 0x40835DF4 at the very
> beginning. The address 0x40835DF4 has 0x00000000.
> 
> Can anybody help me to understand the output?

Well, the output gives you line of code where the block was allocated, e.g.:


 > /usr/local/src/php-5.2.1/ext/imap/php_imap.c(3340) :  Freeing 
0x40836E4C (44
 > bytes), script=/root/compose_multipart.php

Check your code to see what's in this line - that is probably the 
allocation which was not freed.

Usually forgetting to free hashtable generates a number of leak 
messages, since hashtable has main structure, buckets, etc.

-- 
Stanislav Malyshev, Zend Products Engineer
stas@zend.com  http://www.zend.com/
