|
Posted by askel on 10/17/07 20:42
I'm developing small extension that deals with resources. If I use
emalloc/efree for allocating freeing resource data I get random memory
corruption errors. If I replace emalloc/efree with malloc/free,
everything works fine. At least there are no errors produced. I'm
using PHP 4.4.8/Zend Engine 1.3.0/no any optimiser.
-------- myext.c ------
static int le_connections;
struct myconn {
...
}
static void _close_connection(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
struct myconn *conn = (struct myconn *) rsrc->ptr;
/*
Memory corruption happens during or after efree call
*** glibc detected *** php: malloc(): memory corruption: 0x082a5940
***
OR
*** glibc detected *** php: free(): invalid next size (fast):
0x082a58e8 ***
*/
efree(conn);
}
PHP_MINIT_FUNCTION(myext)
{
le_connections =
zend_register_list_destructors_ex(_close_connection, NULL, "my
connection", module_number);
}
PHP_FUNCTION(my_connect)
{
struct myconn *conn;
...
conn = emalloc(sizeof(struct myconn));
...
ZEND_REGISTER_RESOURCE(return_value, conn, le_connections);
}
Navigation:
[Reply to this message]
|