This could be a PHP or COM question... not sure. I am calling a custom COM object from php. I am seeing a memory leak happen when I build my variant in C++ and then return it out to the PHP calling into the COM.
I am using the following piece of code to take a simple C++ array of strings and load it into a Variant: void ComUtils::CreateCOMStrArray(VARIANT* pOut, BSTR* bsArray, int iLen) { SAFEARRAYBOUND bounds = { iLen , 0 } ; SAFEARRAY* pSA = SafeArrayCreate (VT_VARIANT , 1 , &bounds); VARIANT* pVarArray; // lock the array SafeArrayAccessData(pSA , (void **)&pVarArray); // put all strings into variants for (int i=0;i<iLen;i++) { VARIANT vTmp; VariantInit(&vTmp); vTmp.vt = VT_BSTR; vTmp.bstrVal = bsArray[i]; // DANGER DANGER DANGER!!!! VariantCopy(&pVarArray[i], &vTmp); vTmp.bstrVal = NULL; vTmp.vt = VT_EMPTY; // give up string ownership VariantClear(&vTmp); } // unlock the array SafeArrayUnaccessData(pSA); VariantInit(pOut); V_VT(pOut) = VT_ARRAY | VT_VARIANT; // put the array in the output variant V_ARRAY(pOut) = pSA; } Unfortunately, I don't have any COM books, and the VC++ help files don't seem to have what I am looking for (or at least I am looking in the wrong spot). Its pretty obvious to me that the assignment, "vTmp.bstrVal = bsArray[i];" is not the way I shoudl be doing this. PHP doesn't seem to know to free this memory since it was alloc'd outside its realm. So... Is there a PHP fix for this, or is this a COM thing? If it is COM, (I know this is not a COM list) could someone point me in the right direction there? Thanks. // Mike Eynon // www.MikeEynon.com // 1366 Bulb Ave. // Santa Cruz, CA 95062 // [EMAIL PROTECTED] // 831.588.2388 -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php