diff --git a/src/core/RagePhoto.c b/src/core/RagePhoto.c index 38e4b56..659a192 100644 --- a/src/core/RagePhoto.c +++ b/src/core/RagePhoto.c @@ -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; } diff --git a/src/core/RagePhoto.cpp b/src/core/RagePhoto.cpp index 429e1d3..5dbdd98 100644 --- a/src/core/RagePhoto.cpp +++ b/src/core/RagePhoto.cpp @@ -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(malloc(size)); - if (!m_data->jpeg) { + char *t_photoData = static_cast(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; }