Fixed invalid free, discovered by scan-build
This function must return 0 on failure

Dicovered by scan-build