libragephoto: always keep old data when setJpeg malloc fails

This commit is contained in:
Syping 2025-11-05 12:35:09 +01:00
parent 4518ae5aa3
commit f48bd286fe
2 changed files with 8 additions and 6 deletions

View file

@ -1208,12 +1208,13 @@ bool ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t siz
instance->data->jpegSize = size;
}
else if (instance->data->jpegSize < size) {
free(instance->data->jpeg);
instance->data->jpeg = (char*)malloc(size);
if (!instance->data->jpeg) {
char *t_photoData = (char*)malloc(size);
if (!t_photoData) {
instance->data->error = RAGEPHOTO_ERROR_PHOTOMALLOCERROR; // 16
return false;
}
free(instance->data->jpeg);
instance->data->jpeg = t_photoData;
memcpy(instance->data->jpeg, data, size);
instance->data->jpegSize = size;
}

View file

@ -1204,12 +1204,13 @@ bool RagePhoto::setJpeg(const char *data, uint32_t size, uint32_t bufferSize)
m_data->jpegSize = size;
}
else if (m_data->jpegSize < size) {
free(m_data->jpeg);
m_data->jpeg = static_cast<char*>(malloc(size));
if (!m_data->jpeg) {
char *t_photoData = static_cast<char*>(malloc(size));
if (!t_photoData) {
m_data->error = Error::PhotoMallocError; // 16
return false;
}
free(m_data->jpeg);
m_data->jpeg = t_photoData;
memcpy(m_data->jpeg, data, size);
m_data->jpegSize = size;
}