Fixed resource memory leak