From 3ef4fb3ca2de4a1c2e399b61cff2f0016cefbc3a Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sat, 30 Jun 2012 11:43:13 -0300 Subject: [PATCH] tools/libtxt/: make_font takes ownership of the image This way, we don't need to track/free the image separately. --- tools/libtxt/font.c | 11 ++++++----- tools/libtxt/libtxt.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/libtxt/font.c b/tools/libtxt/font.c index bb8b114..6375d6b 100644 --- a/tools/libtxt/font.c +++ b/tools/libtxt/font.c @@ -40,7 +40,7 @@ struct image { }; struct font { - const struct image *img; + struct image *img; struct sym sym[CHARS]; }; @@ -143,7 +143,7 @@ struct image *load_image(const char *name, const char **error) if (err) { if (error) *error = err; - free(img); + free_image(img); return NULL; } return img; @@ -216,7 +216,7 @@ static const char *analyze_font(struct font *font) } -struct font *make_font(const struct image *img, const char **error) +struct font *make_font(struct image *img, const char **error) { struct font *font; const char *err; @@ -229,7 +229,7 @@ struct font *make_font(const struct image *img, const char **error) if (err) { if (error) *error = err; - free(font); + free_font(font); return NULL; } return font; @@ -238,6 +238,7 @@ struct font *make_font(const struct image *img, const char **error) void free_font(struct font *font) { + free_image(font->img); free(font); } @@ -300,7 +301,7 @@ int char_height(const struct font *font, char c) int main(int argc, char **argv) { struct font *font; - const struct image *img; + struct image *img; const char *error; uint8_t canvas[W*H/8] = { 0 }; char *s; diff --git a/tools/libtxt/libtxt.h b/tools/libtxt/libtxt.h index 00ce1ed..f901c52 100644 --- a/tools/libtxt/libtxt.h +++ b/tools/libtxt/libtxt.h @@ -53,7 +53,7 @@ struct edit { struct image *load_image(const char *name, const char **error); void free_image(struct image *img); -struct font *make_font(const struct image *img, const char **error); +struct font *make_font(struct image *img, const char **error); void free_font(struct font *font); int draw_char(void *canvas, int width, int height,