Well I am not that familiar with valgrind but I'll strip anything extraneous out of the program, make sure it still segfaults and then run something like:
$ valgrind --leak-check=full lua purge_database.lua
and see what it spits out.
Tomorrow will be an interesting day indeed :)