Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] Correct use of zend_list_delete [RSS Feed]

#1 Nov. 9, 2005 13:41:20

Marco B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Correct use of zend_list_delete


Maybe this is a question too simple for this list, but I am writingmy first php extension (using php 4.4 SDK) so please, be patient...My extension (rsql) returns a custom struct to php so my code in myrsql_connect looks like:ZEND_FUNCTION(rsql_connect)
{
....
RETURN_RESOURCE(zend_list_insert(rsqldb, rsql_connection));
}

The relevant code is:

ZEND_FUNCTION(rsql_disconnect)
{
...ZEND_FETCH_RESOURCE2(rsqldb, void*, theConnectionParameter, -1,kConnIDString, rsql_connection, rsql_pconnection);if (rsqldb) zend_list_delete(Z_LVAL_PP(theConnectionParameter));
if (rsqldb) myCustomFree(rsqldb);
}

static void rsql_realconnectionclose(zend_rsrc_list_entry *rsrc)
{
void *rsqldb;
if (rsrc != NULL)
{
rsqldb = rsrc->ptr;
if (rsqldb != NULL)
{
rsqlserver_disconnect(rsqldb, kTRUE);
rsqldb = NULL;

if (persistent == kTRUE)
RSQL_G(num_persistent)--;
}
}
}


PHP_MINIT_FUNCTION(rsql)
{rsql_connection = zend_register_list_destructors_ex(rsql_realconnectionclose, NULL, kConnIDString, module_number);}

What is the issue I encounter with this code?
This php code crashes:

for ($i=0; $i<10; $i++){

$dbconn = rsql_connect("127.0.0.1","admin","admin");
if (is_resource($dbconn) == 0){
print "Connection to database server failed.";
exit();
}

rsql_disconnect($dbconn);

}

and also this one:

for ($i=0; $i<10; $i++){

$dbconn = rsql_connect("127.0.0.1","admin","admin");
if (is_resource($dbconn) == 0){
print "Connection to database server failed.";
exit();
}

}What I think is that when rsql_disconnect is called explicitly or bythe destructor (rsql_realconnectionclose) my custom struct isn'treally deleted from the zend_list.I really appreciate any help for my issue...

Thanks a lot,
Marco Bambini

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#2 Nov. 10, 2005 10:55:58

Wez F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Correct use of zend_list_delete


On 11/9/05, Marco Bambini <> wrote:
> ZEND_FUNCTION(rsql_disconnect)
> {
> ...
> ZEND_FETCH_RESOURCE2(rsqldb, void*, theConnectionParameter, -1,
> kConnIDString, rsql_connection, rsql_pconnection);
> if (rsqldb) zend_list_delete(Z_LVAL_PP(theConnectionParameter));
> if (rsqldb) myCustomFree(rsqldb);

Removing the call to myCustomFree should solve your problem; the list
destructor is calling it once for you, and you're then trying to free
somthing that is no longer valid.

--Wez

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » [PHP-DEV] Correct use of zend_list_delete [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support