Reapplied changes.  Still need to work through compile errors.

Re-applied changes to:
  qtest.c
  memory.c
  libqtest.c

Not sure if the changes are correct as I am getting un-related compile
errors.