sshirokov/csgtool — pull request #44 by sshirokov (2013-09-20 10:34:35+00:00)
Title: Plug leaks in bsp_build() and bsp_clip()

**This PR Targets #43**

`bsp_build` and `bsp_clip` leak memory through their helpers. `_build` because it loses track of polygons that are split, and discards them and `_clip` in the opposite way, where created polygons (by `poly_split`) that are clipped are not accounted for, and leaked where the entire input set is reliably deallocated.

This PR attempts to address those problems:

* [x] Plug `bsp_build_*` by tracking unused polygons, and freeing them when `copy` is true
* [ ] Plug `bsp_clip_*` by tracking created polygons, and freeing them when unused

There is also an ugly problem where `bsp_clip_polygons` and `bsp_clip_polygon_array` are almost identical, with a few differences in iteration and counting. This is /also/ terrible:

* [ ] DRY `bsp_clip_polygons` and `bsp_clip_polygon_array`