Fix potential illegal access.

pdf_flush_text can cause the list of gstates to be extended. This
can in turn cause them to move in memory. This means that any
gstate pointers already held can be invalidated.

Update the code to allow for this.
Ensure that pdf_array_delete works even with indirected objects.

Add a RESOLVE(obj) call in line with other such functions.