fix memory leak of pj_ctx if a projection cannot be initialized

This commit is contained in:
Dane Springmeyer 2012-04-11 08:06:29 -07:00
parent bfb0f22788
commit 7cca1489b7

View file

@ -135,10 +135,15 @@ void projection::init()
#if PJ_VERSION >= 480 #if PJ_VERSION >= 480
proj_ctx_ = pj_ctx_alloc(); proj_ctx_ = pj_ctx_alloc();
proj_ = pj_init_plus_ctx(proj_ctx_, params_.c_str()); proj_ = pj_init_plus_ctx(proj_ctx_, params_.c_str());
if (!proj_)
{
if (proj_ctx_) pj_ctx_free(proj_ctx_);
throw proj_init_error(params_);
}
#else #else
proj_ = pj_init_plus(params_.c_str()); proj_ = pj_init_plus(params_.c_str());
#endif
if (!proj_) throw proj_init_error(params_); if (!proj_) throw proj_init_error(params_);
#endif
is_geographic_ = pj_is_latlong(proj_) ? true : false; is_geographic_ = pj_is_latlong(proj_) ? true : false;
} }