Fix memory leak.

PR#2531

(From upstream commit: 44724beeadf95712a42a8b21dc71bf110e89a262)