Fix publicAllocationError reported by cppchek.
Also, it looks the MR prevents a memory leak.
Tag @sroe.