Hi, I am having a problem in my PHP extension and I am wondering if you can give me some advise or even a pointer.
We have the following class object XQueryProcessor and XdmNode. The following method takes the XdmNode as parameter: XQueryProcessor.setContextItem(XdmNode) Any idea what is going wrong in the code below? The XdmNode in my PHP class is a wrapper for a C/C++ object which is held in the XQueryProcessor. Do I have to add some special refcount to the PHP XdmNode? This is giving a memory leak warning: [Fri Sep 22 08:56:42 2017] Script: '/home/ond1/work/svn/latest9.8-saxonc/hec/samples/php/xqueryExamples.php' /home/ond1/work/svn/latest9.8-saxonc/hec/Saxon.C.API/php7_saxon.cpp(3250) : Freeing 0x00007ffff68863c0 (48 bytes), script=/home/ond1/work/svn/latest9.8-saxonc/hec/samples/php/xqueryExamples.php /home/ond1/work/svn/latest9.8-saxonc/hec/Saxon.C.API/php7-src/php-src/Zend/zend_alloc.c(2472) : Actual location (location was relayed) === Total 1 memory leaks detected === The code in question is at follows: PHP_METHOD(XQueryProcessor, setContextItem) { char * context; int len1; zval* oth; XQueryProcessor *xqueryProcessor; if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &oth) == FAILURE) { RETURN_NULL(); } if(oth != NULL) { zend_object* pobj = Z_OBJ_P(getThis()); xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std)); xqueryProcessor = obj->xqueryProcessor; const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name); Z_ADDREF_P(oth); if(strcmp(objName, "Saxon\\XdmNode")==0) { zend_object *vvobj = Z_OBJ_P(oth); xdmNode_object* ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std)); if(ooth != NULL) { XdmNode * value = ooth->xdmNode; if(value != NULL) { Z_ADDREF(*oth); xqueryProcessor->setContextItem((XdmItem *)value); return; } } } else ……. See full code of PHP extension: https://dev.saxonica.com/repos/archive/opensource/latest9.8/hec/Saxon.C.API/php7_saxon.cpp <https://dev.saxonica.com/repos/archive/opensource/latest9.8/hec/Saxon.C.API/php7_saxon.cpp> kind regards, O'Neil ------------------------------- O'Neil Delpratt Software Developer, Saxonica Limited Email: on...@saxonica.com Twitter: https://twitter.com/ond1 Tel: +44 118 946 5894 Web: http://www.saxonica.com Saxonica Community site: http://dev.saxonica.com Bug tracking site: https://saxonica.plan.io/