From: Danny Al-Gaaf Date: Tue, 31 Jan 2017 16:58:44 +0000 (+0100) Subject: rgw/rgw_main.cc: reorder framework detection X-Git-Tag: v12.0.1~462^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cc63f928d67488dcc56cce91a32a1fddc9a78927;p=ceph.git rgw/rgw_main.cc: reorder framework detection Fix for: CID 1398896: Resource leak (RESOURCE_LEAK) overwrite_var: Overwriting fe in fe = new RGWLoadGenFrontend(env, config) leaks the storage that fe points to. Do not check again and again for framework if there is already a match, make use of if/else. This should also fix the RESOURCE_LEAK warning. Signed-off-by: Danny Al-Gaaf --- diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 363807617318..0330e322f4cb 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -458,26 +458,7 @@ int main(int argc, const char **argv) RGWFrontendConfig *config = fiter->second; string framework = config->get_framework(); RGWFrontend *fe = NULL; -#if defined(WITH_RADOSGW_ASIO_FRONTEND) - if ((framework == "asio") && - cct->check_experimental_feature_enabled("rgw-asio-frontend")) { - int port; - config->get_val("port", 80, &port); - std::string uri_prefix; - config->get_val("prefix", "", &uri_prefix); - RGWProcessEnv env{ store, &rest, olog, port, uri_prefix }; - fe = new RGWAsioFrontend(env); - } -#endif /* WITH_RADOSGW_ASIO_FRONTEND */ -#if defined(WITH_RADOSGW_FCGI_FRONTEND) - if (framework == "fastcgi" || framework == "fcgi") { - std::string uri_prefix; - config->get_val("prefix", "", &uri_prefix); - RGWProcessEnv fcgi_pe = { store, &rest, olog, 0, uri_prefix }; - fe = new RGWFCGXFrontend(fcgi_pe, config); - } -#endif /* WITH_RADOSGW_FCGI_FRONTEND */ if (framework == "civetweb" || framework == "mongoose") { int port; config->get_val("port", 80, &port); @@ -488,7 +469,7 @@ int main(int argc, const char **argv) fe = new RGWCivetWebFrontend(env, config); } - if (framework == "loadgen") { + else if (framework == "loadgen") { int port; config->get_val("port", 80, &port); std::string uri_prefix; @@ -498,10 +479,32 @@ int main(int argc, const char **argv) fe = new RGWLoadGenFrontend(env, config); } +#if defined(WITH_RADOSGW_ASIO_FRONTEND) + else if ((framework == "asio") && + cct->check_experimental_feature_enabled("rgw-asio-frontend")) { + int port; + config->get_val("port", 80, &port); + std::string uri_prefix; + config->get_val("prefix", "", &uri_prefix); + RGWProcessEnv env{ store, &rest, olog, port, uri_prefix }; + fe = new RGWAsioFrontend(env); + } +#endif /* WITH_RADOSGW_ASIO_FRONTEND */ +#if defined(WITH_RADOSGW_FCGI_FRONTEND) + else if (framework == "fastcgi" || framework == "fcgi") { + std::string uri_prefix; + config->get_val("prefix", "", &uri_prefix); + RGWProcessEnv fcgi_pe = { store, &rest, olog, 0, uri_prefix }; + + fe = new RGWFCGXFrontend(fcgi_pe, config); + } +#endif /* WITH_RADOSGW_FCGI_FRONTEND */ + if (fe == NULL) { dout(0) << "WARNING: skipping unknown framework: " << framework << dendl; continue; } + dout(0) << "starting handler: " << fiter->first << dendl; int r = fe->init(); if (r < 0) {