Fix memory leak when open_basedir error and improve test