:: commit 7b9600c89312f3921cad2ae9494a30f041c6c52f

mintsuki <mintsuki@protonmail.com> — 2023-03-05 07:47

parents: baf5f6c2ce

image: Use stbi_image_free() instead of freeing buffer ourselves

diff --git a/common/lib/gterm.c b/common/lib/gterm.c
index b01dcd20..523debec 100644
--- a/common/lib/gterm.c
+++ b/common/lib/gterm.c
@@ -804,6 +804,9 @@ no_load_font:;
 
     pmm_free(font, FONT_MAX);
 
+    image_close(background);
+    background = NULL;
+
     if (terms_i == 0) {
         return false;
     }
diff --git a/common/lib/image.c b/common/lib/image.c
index 758ee312..72092b25 100644
--- a/common/lib/image.c
+++ b/common/lib/image.c
@@ -48,7 +48,6 @@ struct image *image_open(struct file_handle *file) {
         pptr[i] = (pptr[i] & 0x0000ff00) | ((pptr[i] & 0x00ff0000) >> 16) | ((pptr[i] & 0x000000ff) << 16);
     }
 
-    image->allocated_size = x * y * 4;
     image->x_size = x;
     image->y_size = y;
     image->pitch = x * 4;
@@ -60,6 +59,6 @@ struct image *image_open(struct file_handle *file) {
 }
 
 void image_close(struct image *image) {
-    pmm_free(image->img, image->allocated_size);
+    stbi_image_free(image->img);
     pmm_free(image, sizeof(struct image));
 }
diff --git a/common/lib/image.h b/common/lib/image.h
index 54997fd0..055c79eb 100644
--- a/common/lib/image.h
+++ b/common/lib/image.h
@@ -5,7 +5,6 @@
 #include <fs/file.h>
 
 struct image {
-    size_t allocated_size;
     size_t x_size;
     size_t y_size;
     int type;
tab: 248 wrap: offon