Fixed CAPI_DestroyStreams.

This commit is contained in:
jsun%netscape.com 1998-09-11 23:17:13 +00:00
parent 9f777defdb
commit 60a5ffbbf5
6 changed files with 38 additions and 20 deletions

View File

@ -37,6 +37,8 @@ CLASS_EXPORT_CAPI nsCalStreamReader
private:
static JulianUtility::MimeEncoding stringToEncodingType(UnicodeString & propVal);
/* dont deallocate these */
JulianPtrArray * m_OutCalendars;
nsCapiCallbackReader * m_Reader;
t_bool m_bParseStarted;
@ -46,6 +48,7 @@ private:
public:
nsCalStreamReader();
~nsCalStreamReader();
nsCalStreamReader(
nsCapiCallbackReader * reader,
JulianPtrArray * outCalendars,

View File

@ -77,6 +77,7 @@ private:
/** encoding of stream */
JulianUtility::MimeEncoding m_Encoding;
/** need to deallocate */
JulianPtrArray * m_Chunks;
static const t_int32 m_MAXBUFFERSIZE;
@ -85,6 +86,7 @@ private:
/* finished getting input from CAPI callback */
t_bool m_bFinished;
/** do not deallocate */
PRMonitor * m_Monitor;
/*-----------------------------
** PRIVATE METHODS

View File

@ -106,7 +106,7 @@ NS_CALENDAR CAPIStatus CAPI_DestroyHandles(
NS_CALENDAR CAPIStatus CAPI_DestroyStreams(
CAPISession s, /* i: login session handle */
CAPIStream* pS, /* i: array of streams to destroy */
int iHandlCount, /* i: number of valid handles in ppH */
int iCount, /* i: number of valid handles in ppH */
long lFlags); /* i: bit flags (none at this time; set to 0) */
NS_CALENDAR CAPIStatus CAPI_FetchEventsByAlarmRange(

View File

@ -397,17 +397,16 @@ CAPIStatus CAPI_DestroyHandles(
}
/**
* Destroy streams: this doesn't make sense. CAPI_Stream is not an
* opaque type.
* Destroy a list of streams
*/
CAPIStatus CAPI_DestroyStreams(
CAPISession s, /* i: login session handle */
CAPIStream* pS, /* i: array of streams to destroy */
int iHandleCount, /* i: number of valid handles in ppH */
int iCount, /* i: number of valid handles in ppH */
long lFlags) /* i: bit flags (none at this time; set to 0) */
{
PCAPIStream** paS;
for (int i = 0; i < iHandleCount; i++)
PCAPIStream** paS = (PCAPIStream **) pS;
for (int i = 0; i < iCount; i++)
delete paS[i];
return CAPI_ERR_OK;
}

View File

@ -44,6 +44,12 @@ nsCalStreamReader::nsCalStreamReader()
//---------------------------------------------------------------------
nsCalStreamReader::~nsCalStreamReader()
{
}
//---------------------------------------------------------------------
nsCalStreamReader::nsCalStreamReader(nsCapiCallbackReader * reader,
JulianPtrArray * outCalendars,
PRThread * thread, void* condVar)

View File

@ -139,8 +139,8 @@ int RcvData(void * pData,
* XXX: may want to ensure that pBuf is 0 terminated.
*/
//pCapiCallbackReader->AddChunk(new UnicodeString(pBuf));
char * pBufCopy = new char[strlen(pBuf)];
strncpy(pBufCopy, pBuf, (size_t) strlen(pBuf));
char * pBufCopy = new char[strlen(pBuf)];
strncpy(pBufCopy, pBuf, (size_t) strlen(pBuf));
nsCapiBufferStruct * capiBuffer = new nsCapiBufferStruct();
capiBuffer->m_pBuf = pBufCopy;
capiBuffer->m_pBufSize = iSize;
@ -331,12 +331,12 @@ nsresult nsCalendarShell::InitialLoadData()
char * psDTEnd = 0;
CAPIStream RcvStream = 0;
CAPIStatus capiStatus;
JulianPtrArray * pParsedCalList = new JulianPtrArray();
nsCalStreamReader * pCalStreamReader = 0;
JulianPtrArray * pParsedCalList = new JulianPtrArray(); // destroyed
nsCalStreamReader * pCalStreamReader = 0; // destroyed
PRThread * parseThread = 0;
PRThread * mainThread = 0;
PRMonitor * pCBReaderMonitor = 0;
PRMonitor *pThreadMonitor = 0;
PRMonitor * pCBReaderMonitor = 0; /// destroyed
PRMonitor *pThreadMonitor = 0; /// destroyed
/*
* Select the capi interface to use for this operation...
@ -363,9 +363,9 @@ nsresult nsCalendarShell::InitialLoadData()
* up here...
*/
mainThread = PR_CurrentThread();
pCBReaderMonitor = PR_NewMonitor();
pCBReaderMonitor = PR_NewMonitor(); // destroyed
nsCapiCallbackReader * capiReader = new nsCapiCallbackReader(pCBReaderMonitor);
pThreadMonitor = ::PR_NewMonitor();
pThreadMonitor = ::PR_NewMonitor(); // destroyed
PR_EnterMonitor(pThreadMonitor);
pCalStreamReader = new nsCalStreamReader(capiReader, pParsedCalList, parseThread, pThreadMonitor);
parseThread = PR_CreateThread(PR_USER_THREAD,
@ -397,7 +397,6 @@ nsresult nsCalendarShell::InitialLoadData()
iListSize = 0;
}
capiStatus = pCapi->CAPI_FetchEventsByRange(
mCAPISession, &mCAPIHandle, 1, 0,
psDTStart, psDTEnd,
@ -417,11 +416,6 @@ nsresult nsCalendarShell::InitialLoadData()
PR_ExitMonitor(pThreadMonitor);
}
delete [] psDTStart; psDTStart = 0;
delete [] psDTEnd; psDTEnd = 0;
PR_DestroyMonitor(pThreadMonitor);
/*
* Load the retrieved events ito our calendar...
*/
@ -444,6 +438,20 @@ nsresult nsCalendarShell::InitialLoadData()
}
}
/**
* cleanup allocated memory
*/
delete [] psDTStart; psDTStart = 0;
delete [] psDTEnd; psDTEnd = 0;
delete pCalStreamReader; pCalStreamReader = 0;
delete capiReader; capiReader = 0;
PR_DestroyMonitor(pThreadMonitor);
PR_DestroyMonitor(pCBReaderMonitor);
/* todo: need to delete calendars in pParsedCalList without deleting events in it */
capiStatus = pCapi->CAPI_DestroyStreams(mCAPISession, &RcvStream, 1, 0);
if (CAPI_ERR_OK != capiStatus)
return 1; /* XXX: really need to fix this up */
/*
* register the calendar...
*/