omit compiler warning by sticking to RAII

gcc warns about uninitialized 'ptr' when using -Wmaybe-uninitialized. It is always good practice to initialize locals.