Clearing a body's shapes

I want to take a b2Body and clear its shapes. I realize that this can be done by destroying the body itself and making a new one, but I want to keep the same b2Body instance.

I was just going to do this:

Code:
for (b2Shape *sh = body->GetShapeList(); sh; sh = sh->GetNext())
{
   body->DestroyShape(sh);
}


but I think that won't work because it'll try to call GetNext after it's been destroyed.

So maybe this would work?

Code:
for (b2Shape *sh = body->GetShapeList(); sh;)
{
   b2Shape *next = sh->GetNext();
   body->DestroyShape(sh);
   sh = next;
}

Original thread: https://box2d.org/forum/viewtopic.php?t=3372