Bug fix for a potential memory leak

Bug fix for a potential memory leak