Fix some memory issues when closing preview UI too fast.
I'm not sure if this pthread usage is ideal, but it does seem to work on linux.
This commit is contained in:
parent
6090f0b0aa
commit
a9e66429d6
@ -1594,16 +1594,19 @@ SaveInfo * Client::GetSave(int saveID, int saveDate)
|
|||||||
tempSave->Favourite = tempFavourite.Value();
|
tempSave->Favourite = tempFavourite.Value();
|
||||||
tempSave->Views = tempViews.Value();
|
tempSave->Views = tempViews.Value();
|
||||||
tempSave->Version = tempVersion.Value();
|
tempSave->Version = tempVersion.Value();
|
||||||
|
free(data);
|
||||||
return tempSave;
|
return tempSave;
|
||||||
}
|
}
|
||||||
catch (json::Exception &e)
|
catch (json::Exception &e)
|
||||||
{
|
{
|
||||||
lastError = "Could not read response";
|
lastError = "Could not read response";
|
||||||
|
free(data);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (data) free(data);
|
||||||
lastError = http_ret_text(dataStatus);
|
lastError = http_ret_text(dataStatus);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -38,27 +38,63 @@ void * PreviewModel::updateSaveCommentsTHelper(void * obj)
|
|||||||
|
|
||||||
void * PreviewModel::updateSaveInfoT()
|
void * PreviewModel::updateSaveInfoT()
|
||||||
{
|
{
|
||||||
|
int check;
|
||||||
|
pthread_attr_t attr;
|
||||||
SaveInfo * tempSave = Client::Ref().GetSave(tSaveID, tSaveDate);
|
SaveInfo * tempSave = Client::Ref().GetSave(tSaveID, tSaveDate);
|
||||||
updateSaveInfoFinished = true;
|
pthread_getattr_np(pthread_self(), &attr);
|
||||||
return tempSave;
|
pthread_attr_getdetachstate(&attr,&check);
|
||||||
|
pthread_attr_destroy(&attr);
|
||||||
|
if (check==PTHREAD_CREATE_JOINABLE)
|
||||||
|
{
|
||||||
|
updateSaveInfoFinished = true;
|
||||||
|
return tempSave;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if (tempSave) delete tempSave;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void * PreviewModel::updateSaveDataT()
|
void * PreviewModel::updateSaveDataT()
|
||||||
{
|
{
|
||||||
int tempDataSize;
|
int tempDataSize, check;
|
||||||
|
pthread_attr_t attr;
|
||||||
unsigned char * tempData = Client::Ref().GetSaveData(tSaveID, tSaveDate, tempDataSize);
|
unsigned char * tempData = Client::Ref().GetSaveData(tSaveID, tSaveDate, tempDataSize);
|
||||||
saveDataBuffer.clear();
|
pthread_getattr_np(pthread_self(), &attr);
|
||||||
if (tempData)
|
pthread_attr_getdetachstate(&attr,&check);
|
||||||
saveDataBuffer.insert(saveDataBuffer.begin(), tempData, tempData+tempDataSize);
|
pthread_attr_destroy(&attr);
|
||||||
updateSaveDataFinished = true;
|
if (check==PTHREAD_CREATE_JOINABLE)
|
||||||
|
{
|
||||||
|
saveDataBuffer.clear();
|
||||||
|
if (tempData)
|
||||||
|
saveDataBuffer.insert(saveDataBuffer.begin(), tempData, tempData+tempDataSize);
|
||||||
|
updateSaveDataFinished = true;
|
||||||
|
}
|
||||||
|
if (tempData) free(tempData);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void * PreviewModel::updateSaveCommentsT()
|
void * PreviewModel::updateSaveCommentsT()
|
||||||
{
|
{
|
||||||
|
int check;
|
||||||
|
pthread_attr_t attr;
|
||||||
std::vector<SaveComment*> * tempComments = Client::Ref().GetComments(tSaveID, (commentsPageNumber-1)*20, 20);
|
std::vector<SaveComment*> * tempComments = Client::Ref().GetComments(tSaveID, (commentsPageNumber-1)*20, 20);
|
||||||
updateSaveCommentsFinished = true;
|
pthread_getattr_np(pthread_self(), &attr);
|
||||||
return tempComments;
|
pthread_attr_getdetachstate(&attr,&check);
|
||||||
|
pthread_attr_destroy(&attr);
|
||||||
|
if (check==PTHREAD_CREATE_JOINABLE)
|
||||||
|
{
|
||||||
|
updateSaveCommentsFinished = true;
|
||||||
|
return tempComments;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
for(int i = 0; i < tempComments->size(); i++)
|
||||||
|
delete tempComments->at(i);
|
||||||
|
tempComments->clear();
|
||||||
|
delete tempComments;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewModel::SetFavourite(bool favourite)
|
void PreviewModel::SetFavourite(bool favourite)
|
||||||
@ -307,6 +343,12 @@ void PreviewModel::Update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
PreviewModel::~PreviewModel() {
|
PreviewModel::~PreviewModel() {
|
||||||
|
//pthread_join(updateSaveDataThread, NULL);
|
||||||
|
//pthread_join(updateSaveInfoThread, NULL);
|
||||||
|
//pthread_join(updateSaveCommentsThread, NULL);
|
||||||
|
if (updateSaveDataWorking) pthread_detach(updateSaveDataThread);
|
||||||
|
if (updateSaveInfoWorking) pthread_detach(updateSaveInfoThread);
|
||||||
|
if (updateSaveCommentsWorking) pthread_detach(updateSaveCommentsThread);
|
||||||
if(save)
|
if(save)
|
||||||
delete save;
|
delete save;
|
||||||
if(saveComments)
|
if(saveComments)
|
||||||
@ -314,6 +356,7 @@ PreviewModel::~PreviewModel() {
|
|||||||
for(int i = 0; i < saveComments->size(); i++)
|
for(int i = 0; i < saveComments->size(); i++)
|
||||||
delete saveComments->at(i);
|
delete saveComments->at(i);
|
||||||
saveComments->clear();
|
saveComments->clear();
|
||||||
|
delete saveComments;
|
||||||
}
|
}
|
||||||
saveDataBuffer.clear();
|
saveDataBuffer.clear();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user