Fix use after free. Fix thread launching.

This commit is contained in:
Learath Lea 2015-02-27 23:06:19 +02:00
parent 422e726dce
commit 8ee294a412
3 changed files with 15 additions and 5 deletions

View file

@ -43,10 +43,14 @@ void CFetcher::QueueAdd(CFetchTask *pTask, const char *pUrl, const char *pDest,
pTask->m_Abort = false;
lock_wait(m_Lock);
if(!m_pThHandle)
{
m_pThHandle = thread_create(&FetcherThread, this);
thread_detach(m_pThHandle);
}
if(!m_pFirst)
{
void *pHandle = thread_create(&FetcherThread, this);
thread_detach(pHandle);
m_pFirst = pTask;
m_pLast = m_pFirst;
}
@ -99,7 +103,10 @@ bool CFetcher::FetchFile(CFetchTask *pTask)
}
}
IOHANDLE File = m_pStorage->OpenFile(pTask->m_pDest, IOFLAG_WRITE, pTask->m_StorageType);
char aPath[256];
m_pStorage->GetCompletePath(pTask->m_StorageType, pTask->m_pDest, aPath, sizeof(aPath));
IOHANDLE File = io_open(aPath, IOFLAG_WRITE);
char aErr[CURL_ERROR_SIZE];
curl_easy_setopt(m_pHandle, CURLOPT_ERRORBUFFER, aErr);
@ -126,10 +133,10 @@ bool CFetcher::FetchFile(CFetchTask *pTask)
return false;
}
io_close(File);
dbg_msg("fetcher", "Task done %s", pTask->m_pDest);
pTask->m_State = CFetchTask::STATE_DONE;
if(pTask->m_pfnCompCallback)
pTask->m_pfnCompCallback(pTask, pTask->m_pUser);
dbg_msg("fetcher", "Task done %s", pTask->m_pDest);
pTask->m_State = CFetchTask::STATE_DONE;
return true;
}

View file

@ -11,6 +11,8 @@ class CFetcher : public IFetcher
private:
CURL *m_pHandle;
void *m_pThHandle;
LOCK m_Lock;
CFetchTask *m_pFirst;
CFetchTask *m_pLast;

View file

@ -2,6 +2,7 @@
#define ENGINE_FETCHER_H
#include "kernel.h"
#include "stddef.h"
class CFetchTask;