gh-38432: fix memory leak in is_planar
Fixes the memory leak in `is_planar` reported at
https://ask.sagemath.org/question/78467/memory-leak-in-is_planar/
We now ensure that memory is released before returning the answer.
### :memo: Checklist
<!-- Put an `x` in all the boxes that apply. -->
- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
### :hourglass: Dependencies
<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - #12345: short description why this is a dependency -->
<!-- - #34567: ... -->
URL: https://github.com/sagemath/sage/pull/38432
Reported by: David Coudert
Reviewer(s): Travis Scrimshaw