CPerlHost::~CPerlHost(void)
{
-// Reset();
+ Reset();
InterlockedDecrement(&num_hosts);
delete m_pvDir;
m_pVMemParse->Release();
LPSTR*
CPerlHost::Lookup(LPCSTR lpStr)
{
+ if (!lpStr)
+ return NULL;
return (LPSTR*)bsearch(&lpStr, m_lppEnvList, m_dwEnvCount, sizeof(LPSTR), lookup);
}
// replacing ?
lpPtr = Lookup(szBuffer);
- if(lpPtr != NULL) {
- Renew(*lpPtr, length, char);
+ if (lpPtr != NULL) {
+ // must allocate things via host memory allocation functions
+ // rather than perl's Renew() et al, as the perl interpreter
+ // may either not be initialized enough when we allocate these,
+ // or may already be dead when we go to free these
+ *lpPtr = (char*)Realloc(*lpPtr, length * sizeof(char));
strcpy(*lpPtr, lpStr);
}
else {
- ++m_dwEnvCount;
- Renew(m_lppEnvList, m_dwEnvCount, LPSTR);
- New(1, m_lppEnvList[m_dwEnvCount-1], length, char);
- if(m_lppEnvList[m_dwEnvCount-1] != NULL) {
- strcpy(m_lppEnvList[m_dwEnvCount-1], lpStr);
- qsort(m_lppEnvList, m_dwEnvCount, sizeof(LPSTR), compare);
+ m_lppEnvList = (LPSTR*)Realloc(m_lppEnvList, (m_dwEnvCount+1) * sizeof(LPSTR));
+ if (m_lppEnvList) {
+ m_lppEnvList[m_dwEnvCount] = (char*)Malloc(length * sizeof(char));
+ if (m_lppEnvList[m_dwEnvCount] != NULL) {
+ strcpy(m_lppEnvList[m_dwEnvCount], lpStr);
+ ++m_dwEnvCount;
+ qsort(m_lppEnvList, m_dwEnvCount, sizeof(LPSTR), compare);
+ }
}
- else
- --m_dwEnvCount;
}
}
dTHX;
if(m_lppEnvList != NULL) {
for(DWORD index = 0; index < m_dwEnvCount; ++index) {
- Safefree(m_lppEnvList[index]);
+ Free(m_lppEnvList[index]);
m_lppEnvList[index] = NULL;
}
}
m_dwEnvCount = 0;
+ Free(m_lppEnvList);
+ m_lppEnvList = NULL;
}
void