1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

stbi: fix memory leak from stbi.load/1 with GC (#16028)

This commit is contained in:
Wertzui123
2022-10-11 14:19:36 +02:00
committed by GitHub
parent 34f233c93f
commit 5047058595
4 changed files with 69 additions and 1 deletions

View File

@ -4,6 +4,31 @@
module stbi
[if trace_stbi_allocations ?]
fn trace_allocation(message string) {
eprintln(message)
}
[export: 'stbi__callback_malloc']
fn cb_malloc(s usize) voidptr {
res := unsafe { malloc(isize(s)) }
trace_allocation('> stbi__callback_malloc: $s => ${ptr_str(res)}')
return res
}
[export: 'stbi__callback_realloc']
fn cb_realloc(p voidptr, s usize) voidptr {
res := unsafe { v_realloc(p, isize(s)) }
trace_allocation('> stbi__callback_realloc: ${ptr_str(p)} , $s => ${ptr_str(res)}')
return res
}
[export: 'stbi__callback_free']
fn cb_free(p voidptr) {
trace_allocation('> stbi__callback_free: ${ptr_str(p)}')
unsafe { free(p) }
}
#flag -I @VEXEROOT/thirdparty/stb_image
#include "stb_image.h"
#include "stb_image_write.h"