summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-11-06 18:36:29 -0400
committerTavian Barnes <tavianator@gmail.com>2010-11-06 18:36:29 -0400
commitd3250a168254ebc6aa0087dfcfee5d7dfead9703 (patch)
treeb262caaa7ed6ef2cb2c8cd7c142381eb96a85149
parentd7e9d913730b96a83751863ad896648488296532 (diff)
downloaddimension-d3250a168254ebc6aa0087dfcfee5d7dfead9703.tar.xz
Don't leak patterns in color_map pigments.
-rw-r--r--libdimension/color_map.c11
-rw-r--r--tests/libdimension/render.c3
2 files changed, 12 insertions, 2 deletions
diff --git a/libdimension/color_map.c b/libdimension/color_map.c
index e0ddcd3..4832e87 100644
--- a/libdimension/color_map.c
+++ b/libdimension/color_map.c
@@ -85,6 +85,15 @@ typedef struct dmnsn_color_map_payload {
dmnsn_color_map *map;
} dmnsn_color_map_payload;
+static void
+dmnsn_delete_color_map_payload(void *ptr)
+{
+ dmnsn_color_map_payload *payload = ptr;
+ dmnsn_delete_color_map(payload->map);
+ dmnsn_delete_pattern(payload->pattern);
+ dmnsn_free(payload);
+}
+
static dmnsn_color
dmnsn_color_map_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v)
{
@@ -114,7 +123,7 @@ dmnsn_new_color_map_pigment(dmnsn_pattern *pattern, dmnsn_color_map *map)
pigment->pigment_fn = &dmnsn_color_map_pigment_fn;
pigment->init_fn = &dmnsn_color_map_init_fn;
- pigment->free_fn = &dmnsn_free;
+ pigment->free_fn = &dmnsn_delete_color_map_payload;
pigment->ptr = payload;
return pigment;
}
diff --git a/tests/libdimension/render.c b/tests/libdimension/render.c
index bc662d3..d4c5edc 100644
--- a/tests/libdimension/render.c
+++ b/tests/libdimension/render.c
@@ -148,13 +148,14 @@ dmnsn_new_test_scene(void)
torii->texture->pigment = dmnsn_new_solid_pigment(dmnsn_blue);
torii->texture->finish = dmnsn_new_ambient_finish(dmnsn_white);
dmnsn_array_push(scene->objects, &torii);
+ dmnsn_delete_array(torus_array);
dmnsn_object *plane = dmnsn_new_plane(dmnsn_new_vector(0.0, 1.0, 0.0));
plane->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -2.0, 0.0));
plane->texture = dmnsn_new_texture();
dmnsn_pattern *checker = dmnsn_new_checker_pattern();
dmnsn_color_map *color_map = dmnsn_new_color_map();
- dmnsn_add_color_map_entry(color_map, 0.5, dmnsn_black);
+ dmnsn_add_color_map_entry(color_map, 0.0, dmnsn_black);
dmnsn_add_color_map_entry(color_map, 1.0, dmnsn_white);
plane->texture->pigment = dmnsn_new_color_map_pigment(checker, color_map);
dmnsn_array_push(scene->objects, &plane);