src/svgtiny.c: deallocate stylesheets during finalisation
We allocate stylesheets in svgtiny_parse_style_element() and append
them to our global select_ctx, but the select_ctx retains only a const
reference to them and is not responsible for freeing their resources.
Instead, we have to do it during finalisation.
This is a little ugly because we have to de-const the sheet references
before we can destroy them. This relies on the non-local knowledge
that every sheet appended to the context does in fact originate in the
one function svgtiny_parse_style_element(). On the other hand, using
the context to keep track of these sheets saves us the trouble of
maintaining a duplicate array that would differ only in type
signature.
In summary:
* The sheets are now removed from the context before destroying
them. This avoids a potential issue where destroying the context
itself (which we do afterwards) might try to access the sheets.
* If we fail to obtain a pointer to a sheet, we stop processing that
sheet. This should not happen, and if something extremely weird
happens it can hide the problem, but that's still better than the
segfault we'd get from trying to operate on an invalid pointer.
* The sheets are removed/destroyed in reverse order, last-in
first-out.
* Extremely unlikely error paths call assert(). Production builds
will still catch and propagate errors.