brewery
notashelf /
dc9f159470cb818cdddff1cd0dd6ee083be50eed

chroma

public

Lightweight wallpaper daemon for Wayland

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/chroma.git

Commit dc9f159470cb

tarball

NotAShelf <raf@notashelf.dev> · 2026-05-17 21:23 UTC

unverified1 files changed+8-3
image: fix allocator tracking; prevent double-free on release

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ia24b68cd4850a7749cd10643e5423b646a6a6964
diff --git a/src/image.c b/src/image.cindex ef63c4c..a424a7e 100644--- a/src/image.c+++ b/src/image.c@@ -143,6 +143,7 @@ int chroma_image_load(chroma_image_t *image, const char *path,   image->data = stbi_load(path, &image->width, &image->height, &image->channels,                           desired_channels);   image->channels = desired_channels;+  image->data_from_stbi = true;   if (!image->data) {     chroma_log("ERROR", "Failed to load image %s: %s", path,                stbi_failure_reason());@@ -227,6 +228,7 @@ int chroma_image_load(chroma_image_t *image, const char *path,      stbi_image_free(image->data);     image->data = downsampled_data;+    image->data_from_stbi = false;     image->width = optimal_width;     image->height = optimal_height; @@ -271,8 +273,11 @@ void chroma_image_free(chroma_image_t *image) {      chroma_log_resource_deallocation("image_data", image_size, image->path); -    // Always use stbi_image_free since we load directly with stbi_load-    stbi_image_free(image->data);+    if (image->data_from_stbi) {+      stbi_image_free(image->data);+    } else {+      free(image->data);+    }     image->data = NULL;   } @@ -291,7 +296,7 @@ void chroma_image_free(chroma_image_t *image) {  // Release a reference to an image; free when ref_count reaches zero void chroma_image_release(chroma_image_t *image) {-  if (!image) {+  if (!image || !image->loaded) {     return;   }