aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorMarvin Borner2021-04-18 13:05:33 +0200
committerMarvin Borner2021-04-18 13:05:33 +0200
commite1fea940e4c642b1c883429ed5f2a69d51b84270 (patch)
tree79884ba0ccdb9575553f4fb75e176cea31bb9cd6 /libs
parentcdf029471736f43776452930b7195a06ab143654 (diff)
Fixed some memory leaks
Diffstat (limited to 'libs')
-rw-r--r--libs/libgui/gfx.c17
-rw-r--r--libs/libgui/gfx.h1
-rw-r--r--libs/libgui/psf.c1
-rw-r--r--libs/libtxt/keymap.c1
4 files changed, 20 insertions, 0 deletions
diff --git a/libs/libgui/gfx.c b/libs/libgui/gfx.c
index db09d21..c26f59a 100644
--- a/libs/libgui/gfx.c
+++ b/libs/libgui/gfx.c
@@ -59,6 +59,16 @@ static void load_font(enum font_type font_type)
assert(fonts[font_type]);
}
+static void free_fonts(void)
+{
+ for (u8 i = 0; i < FONT_COUNT; i++) {
+ if (fonts[i]) {
+ free(fonts[i]->raw);
+ free(fonts[i]);
+ }
+ }
+}
+
static void write_char(struct context *ctx, vec2 pos, struct font *font, u32 c, char ch)
{
int bypp = ctx->bpp >> 3;
@@ -107,8 +117,14 @@ struct context *gfx_new_ctx(struct context *ctx, vec2 size, u8 bpp)
}
// On-demand font loading
+static u8 fonts_loaded = 0;
struct font *gfx_resolve_font(enum font_type font_type)
{
+ if (!fonts_loaded) {
+ fonts_loaded = 1;
+ atexit(free_fonts);
+ }
+
if (!fonts[font_type])
load_font(font_type);
return fonts[font_type];
@@ -187,6 +203,7 @@ void gfx_load_image_filter(struct context *ctx, vec2 pos, enum gfx_filter filter
srcfb += bmp.pitch - diff;
destfb += ctx->pitch - diff;
}
+ free(bmp.data);
}
void gfx_load_image(struct context *ctx, vec2 pos, const char *path)
diff --git a/libs/libgui/gfx.h b/libs/libgui/gfx.h
index f01a6a2..c3fe5d3 100644
--- a/libs/libgui/gfx.h
+++ b/libs/libgui/gfx.h
@@ -53,6 +53,7 @@ enum gfx_filter {
// Generalized font struct
struct font {
+ void *raw;
char *chars;
vec2 size;
int char_size;
diff --git a/libs/libgui/psf.c b/libs/libgui/psf.c
index 751421a..95678ed 100644
--- a/libs/libgui/psf.c
+++ b/libs/libgui/psf.c
@@ -48,6 +48,7 @@ struct font *psf_parse(char *data)
}
struct font *font = malloc(sizeof(*font));
+ font->raw = data;
font->chars = chars;
font->size.x = width;
font->size.y = height;
diff --git a/libs/libtxt/keymap.c b/libs/libtxt/keymap.c
index 67054f6..9e65bf9 100644
--- a/libs/libtxt/keymap.c
+++ b/libs/libtxt/keymap.c
@@ -84,6 +84,7 @@ struct keymap *keymap_parse(const char *path)
map(keymap, line, ch, ch_index);
index++;
}
+ free(keymap_src);
return keymap;
}