Fixed memory leak when insertion fails.