BUG/MEDIUM: pattern: fixup use_after_free in the pat_ref_delete_by_id

I found there is use_after_free bug in the pat_ref_delete_by_id.

[wt: it seems this fix must be backported to 1.5 as well]

(cherry picked from commit aede6ddd1f3a9ad553bc17eba9b0b1d09094b3ca)
1 file changed