#include <string.h>
#include "imago2.h"
#include "ftmodule.h"
+#include "chkalloc.h"
static int pixel_size(enum img_fmt fmt);
static size_t def_read(void *buf, size_t bytes, void *uptr);
void img_destroy(struct img_pixmap *img)
{
- free(img->pixels);
+ chk_free(img->pixels);
img->pixels = 0; /* just in case... */
img->width = img->height = 0xbadbeef;
- free(img->name);
+ chk_free(img->name);
}
struct img_pixmap *img_create(void)
{
struct img_pixmap *p;
- if(!(p = malloc(sizeof *p))) {
+ if(!(p = chk_malloc(sizeof *p))) {
return 0;
}
img_init(p);
void img_free(struct img_pixmap *img)
{
img_destroy(img);
- free(img);
+ chk_free(img);
}
int img_set_name(struct img_pixmap *img, const char *name)
{
char *tmp;
- if(!(tmp = malloc(strlen(name) + 1))) {
+ if(!(tmp = chk_malloc(strlen(name) + 1))) {
return -1;
}
strcpy(tmp, name);
void *newpix;
int pixsz = pixel_size(fmt);
- if(!(newpix = malloc(w * h * pixsz))) {
+ if(!(newpix = chk_malloc(w * h * pixsz))) {
return -1;
}
memset(newpix, 0, w * h * pixsz);
}
- free(img->pixels);
+ chk_free(img->pixels);
img->pixels = newpix;
img->width = w;
img->height = h;
void img_free_pixels(void *pix)
{
- free(pix);
+ chk_free(pix);
}
int img_load(struct img_pixmap *img, const char *fname)