Ah, many thanks for the pointer. I ended up building it with "debuild -b -uc -us" to avoid the signing error with dpkg-buildpackage.
I can confirm that removing the poptFreeContext(poptctxt) before using the filename and then adding poptFreeContext(poptctxt) before each exit() call and the return keyword does fix the issue (see attached diff file).
Ah, many thanks for the pointer. I ended up building it with "debuild -b -uc -us" to avoid the signing error with dpkg-buildpackage.
I can confirm that removing the poptFreeContext (poptctxt) before using the filename and then adding poptFreeContext (poptctxt) before each exit() call and the return keyword does fix the issue (see attached diff file).