Fix potential memory leak introduced in commit 2b98f98beb