I think that this patch is basically correct, except that it's not correct to set mqh_counterparty_attached when receiver is still NULL. Here's a v2 where I've attempted to correct that while preserving the essence of your proposed fix.
This looks good to me,
I'm not sure that we need a shm_mq_flush(), but we definitely don't have one currently, so I've also adjusted your patch to remove the dead prototype.