match malloc with free; check for NULL