Skip to content

Commit

Permalink
rgw/rgw_main.cc: reorder framework detection
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dalgaaf authored and liewegas committed Feb 9, 2017
1 parent 33de6f7 commit cc63f92
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/rgw/rgw_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit cc63f92

Please sign in to comment.