libragephoto: always keep old data when setJpeg malloc fails
This commit is contained in:
parent
4518ae5aa3
commit
f48bd286fe
2 changed files with 8 additions and 6 deletions
|
|
@ -1208,12 +1208,13 @@ bool ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t siz
|
||||||
instance->data->jpegSize = size;
|
instance->data->jpegSize = size;
|
||||||
}
|
}
|
||||||
else if (instance->data->jpegSize < size) {
|
else if (instance->data->jpegSize < size) {
|
||||||
free(instance->data->jpeg);
|
char *t_photoData = (char*)malloc(size);
|
||||||
instance->data->jpeg = (char*)malloc(size);
|
if (!t_photoData) {
|
||||||
if (!instance->data->jpeg) {
|
|
||||||
instance->data->error = RAGEPHOTO_ERROR_PHOTOMALLOCERROR; // 16
|
instance->data->error = RAGEPHOTO_ERROR_PHOTOMALLOCERROR; // 16
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
free(instance->data->jpeg);
|
||||||
|
instance->data->jpeg = t_photoData;
|
||||||
memcpy(instance->data->jpeg, data, size);
|
memcpy(instance->data->jpeg, data, size);
|
||||||
instance->data->jpegSize = size;
|
instance->data->jpegSize = size;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1204,12 +1204,13 @@ bool RagePhoto::setJpeg(const char *data, uint32_t size, uint32_t bufferSize)
|
||||||
m_data->jpegSize = size;
|
m_data->jpegSize = size;
|
||||||
}
|
}
|
||||||
else if (m_data->jpegSize < size) {
|
else if (m_data->jpegSize < size) {
|
||||||
free(m_data->jpeg);
|
char *t_photoData = static_cast<char*>(malloc(size));
|
||||||
m_data->jpeg = static_cast<char*>(malloc(size));
|
if (!t_photoData) {
|
||||||
if (!m_data->jpeg) {
|
|
||||||
m_data->error = Error::PhotoMallocError; // 16
|
m_data->error = Error::PhotoMallocError; // 16
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
free(m_data->jpeg);
|
||||||
|
m_data->jpeg = t_photoData;
|
||||||
memcpy(m_data->jpeg, data, size);
|
memcpy(m_data->jpeg, data, size);
|
||||||
m_data->jpegSize = size;
|
m_data->jpegSize = size;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue