Test case for #508 

Hello, 

Here's test case for #508 .

Hangs in current trunk, works OK with fix from #512 .