Skip to content

feat: add free_sd_images function to manage memory for C API#1633

Open
Cyberhan123 wants to merge 1 commit into
leejet:masterfrom
Cyberhan123:ffi-api
Open

feat: add free_sd_images function to manage memory for C API#1633
Cyberhan123 wants to merge 1 commit into
leejet:masterfrom
Cyberhan123:ffi-api

Conversation

@Cyberhan123

Copy link
Copy Markdown
Contributor

Summary

This is part of #1368.
This pull request introduces a new memory management function to the C API for handling image arrays, which is especially important for Windows compatibility. The main change is the addition of a free_sd_images function to safely free memory allocated for image arrays, preventing issues related to mismatched C runtime libraries.

Memory management improvements

  • Added a new API function free_sd_images to both the stable-diffusion.h header and the implementation in stable-diffusion.cpp. This function ensures that memory allocated for image arrays (sd_image_t*) is properly freed, addressing potential CRT (C Runtime) issues on Windows when memory is allocated in the library but freed in the caller.

Checklist

Copilot AI review requested due to automatic review settings June 11, 2026 03:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a C-API helper to centralize deallocation of image buffers returned by the library, primarily to avoid Windows CRT mismatches when callers free memory allocated inside the DLL.

Changes:

  • Added free_sd_images(sd_image_t* result_images, int num_images) implementation to free per-image buffers plus the image array.
  • Exposed the new function in the public header with guidance for C API callers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/stable-diffusion.cpp Implements free_sd_images to free image data buffers and the containing array.
include/stable-diffusion.h Declares the new API and documents intended ownership/freeing pattern for C callers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/stable-diffusion.cpp
Comment thread include/stable-diffusion.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants