diff options
author | tavianator <tavianator@antimatter.localdomain> | 2009-12-27 13:12:56 -0700 |
---|---|---|
committer | tavianator <tavianator@antimatter.localdomain> | 2009-12-27 13:12:56 -0700 |
commit | 2fab7d7ff6b926e79c35be3e59b42e733f8bf33c (patch) | |
tree | aab6809540e05b97844dec8cfac89415af9aa8c2 /libdimension/finishes.c | |
parent | a9ce26a1cd786690b4b8f4b54fc7077b3d3569e5 (diff) | |
download | dimension-2fab7d7ff6b926e79c35be3e59b42e733f8bf33c.tar.xz |
Clean up finish combination allocation semantics.
Diffstat (limited to 'libdimension/finishes.c')
-rw-r--r-- | libdimension/finishes.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/libdimension/finishes.c b/libdimension/finishes.c index a8347bd..a1b10e7 100644 --- a/libdimension/finishes.c +++ b/libdimension/finishes.c @@ -78,23 +78,37 @@ dmnsn_finish_combination_free_fn(void *ptr) dmnsn_finish * dmnsn_new_finish_combination(dmnsn_finish *f1, dmnsn_finish *f2) { - dmnsn_finish *finish = dmnsn_new_finish(); - if (finish) { - dmnsn_finish **params = malloc(2*sizeof(dmnsn_finish *)); - if (!params) { - dmnsn_delete_finish(finish); - return NULL; + if (f1 && f2) { + dmnsn_finish *finish = dmnsn_new_finish(); + if (finish) { + dmnsn_finish **params = malloc(2*sizeof(dmnsn_finish *)); + if (!params) { + dmnsn_delete_finish(finish); + dmnsn_delete_finish(f2); + dmnsn_delete_finish(f1); + return NULL; + } + + params[0] = f1; + params[1] = f2; + + finish->ptr = params; + finish->finish_fn = &dmnsn_finish_combination_fn; + finish->ambient_fn = &dmnsn_finish_combination_ambient_fn; + finish->free_fn = &dmnsn_finish_combination_free_fn; + + return finish; + } else { + dmnsn_delete_finish(f2); + dmnsn_delete_finish(f1); } - - params[0] = f1; - params[1] = f2; - - finish->ptr = params; - finish->finish_fn = &dmnsn_finish_combination_fn; - finish->ambient_fn = &dmnsn_finish_combination_ambient_fn; - finish->free_fn = &dmnsn_finish_combination_free_fn; + } else if (f1) { + dmnsn_delete_finish(f1); + } else if (f2) { + dmnsn_delete_finish(f2); } - return finish; + + return NULL; } /* |