diff --git a/include/SFML/Graphics/Image.h b/include/SFML/Graphics/Image.h index 679a5250..c16a06c9 100644 --- a/include/SFML/Graphics/Image.h +++ b/include/SFML/Graphics/Image.h @@ -169,9 +169,6 @@ CSFML_GRAPHICS_API sfBool sfImage_saveToFile(const sfImage* image, const char* f /// This function fails if the image is empty, or if /// the format was invalid. /// -/// The array pointed to by \p buffer must be freed to prevent -/// a memory leak. -/// /// \param image Image object /// \param buffer Address of buffer to fill with encoded data /// \param size Size of buffer diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index c4e7fd46..ec81c806 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -139,14 +139,10 @@ sfBool sfImage_saveToMemory(const sfImage* image, unsigned char** buffer, size_t { CSFML_CHECK_RETURN(image, sfFalse); - std::vector output; + static std::vector output; if (image->This.saveToMemory(output, format)){ - // Create new buffer then return address and size to user - *buffer = reinterpret_cast(std::malloc(output.size())); + *buffer = &output[0]; *size = output.size(); - - // Copy vector contents into buffer - std::memcpy(*buffer, &output[0], output.size()); return sfTrue; }