summaryrefslogtreecommitdiffstats
path: root/libdimension/raytrace.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-10-19 00:49:29 +0000
committerTavian Barnes <tavianator@gmail.com>2009-10-19 00:49:29 +0000
commit95895823f75108cbfed2697498e4e097f493b236 (patch)
tree77efe89b445f168b7d0c63f3fd5f0a23f6e743e8 /libdimension/raytrace.c
parent8710689500d3d35d04aabd727f12698590a816cb (diff)
downloaddimension-95895823f75108cbfed2697498e4e097f493b236.tar.xz
Fix some memory leaks.
dmnsn_delete_pigment() was not using the free_fn, and kD splay trees were not being deleted after raytracing finished.
Diffstat (limited to 'libdimension/raytrace.c')
-rw-r--r--libdimension/raytrace.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 3e67c4b..bb88940 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -140,7 +140,7 @@ dmnsn_raytrace_scene_multithread(dmnsn_raytrace_payload *payload)
payloads[i].threads = nthreads;
if (i > 0) {
payloads[i].kD_splay_tree =
- dmnsn_kD_splay_copy(payloads[i].kD_splay_tree);
+ dmnsn_kD_splay_copy(payloads[0].kD_splay_tree);
}
if (pthread_create(&threads[i], NULL,
@@ -148,11 +148,14 @@ dmnsn_raytrace_scene_multithread(dmnsn_raytrace_payload *payload)
&payloads[i]) != 0)
{
for (j = 0; j < i; ++j) {
- if (pthread_join(threads[i], &ptr)) {
+ if (pthread_join(threads[j], &ptr)) {
dmnsn_error(DMNSN_SEVERITY_MEDIUM,
"Couldn't join worker thread in failed raytrace engine"
" initialization.");
} else {
+ /* Only free on a successful join - otherwise we might free a pointer
+ out from under a running thread */
+ dmnsn_delete_kD_splay_tree(payloads[j].kD_splay_tree);
free(ptr);
}
}
@@ -170,6 +173,7 @@ dmnsn_raytrace_scene_multithread(dmnsn_raytrace_payload *payload)
if (retval == 0) {
retval = *(int *)ptr;
}
+ dmnsn_delete_kD_splay_tree(payloads[i].kD_splay_tree);
free(ptr);
}
}