Should use pool associated with rdata, not tdata here - the pool is only used for an intermediate result, so doesn't need the longer lifetime associated with the tdata.  As per other comments, would be better to just pass the rdata to the routine to avoid opening up this possibility.