I would clear the buffer only if psize == tctx->temp_buffer_len