Writing a PHP extension in C++, and memory leaks

From: Date: Fri, 14 Sep 2012 11:40:13 +0000
Subject: Writing a PHP extension in C++, and memory leaks
Groups: php.internals 
Request: Send a blank email to internals+get-63005@lists.php.net to get a copy of this message
Is it safe to write PHP extensions in C++? I read on Sara Golemon's book that the zend engine can bailout on a request during a call to php_error_docref() or even an emaloc() that exceeds the allowed memory,  doing an immediate longjmp() to the shutdown part of the engine. longjmp() does not work well with C++ destructors. For example: [code] void some_function( TSRMLS_D ) {  Someclass obj( 3 );  char *dst = emalloc(Morethanscriptlimit);  ...   void some_function( TSRMLS_D ) {  Someclass obj( 3 );   php_error_docref( NULL TSRMLS_CC, E_ERROR, "Some error" );  ... [/code] in these two cases ~Someclass() may never be invoked on obj, if either php_error_docref() or emalloc calls longjmp().

« previous php.internals (#63005) next »