diff --git a/src/factory/WFTaskFactory.inl b/src/factory/WFTaskFactory.inl index 6687e0df..a526a867 100644 --- a/src/factory/WFTaskFactory.inl +++ b/src/factory/WFTaskFactory.inl @@ -303,45 +303,39 @@ void WFComplexClientTask::init(TransportType type, template bool WFComplexClientTask::set_port() { - int port = 0; - - if (uri_.port && uri_.port[0]) + if (uri_.port) { - port = atoi(uri_.port); - if (port < 0 || port > 65535) + int port = atoi(uri_.port); + + if (port <= 0 || port > 65535) { this->state = WFT_STATE_TASK_ERROR; this->error = WFT_ERR_URI_PORT_INVALID; return false; } + + return true; } - if (port == 0 && uri_.scheme) + if (uri_.scheme) { const char *port_str = WFGlobal::get_default_port(uri_.scheme); if (port_str) { - size_t port_len = strlen(port_str); - + uri_.port = strdup(port_str); if (uri_.port) - free(uri_.port); + return true; - uri_.port = (char *)malloc(port_len + 1); - if (!uri_.port) - { - uri_.state = URI_STATE_ERROR; - uri_.error = errno; - this->state = WFT_STATE_SYS_ERROR; - this->error = errno; - return false; - } - - memcpy(uri_.port, port_str, port_len + 1); + this->state = WFT_STATE_SYS_ERROR; + this->error = errno; + return false; } } - return true; + this->state = WFT_STATE_TASK_ERROR; + this->error = WFT_ERR_URI_SCHEME_INVALID; + return false; } template diff --git a/src/manager/WFGlobal.cc b/src/manager/WFGlobal.cc index a838cf5c..8bdd14da 100644 --- a/src/manager/WFGlobal.cc +++ b/src/manager/WFGlobal.cc @@ -60,19 +60,22 @@ public: settings_ = *settings; } - const char *get_default_port(const std::string& scheme) const + const char *get_default_port(const std::string& scheme) { const auto it = static_scheme_port_.find(scheme); if (it != static_scheme_port_.end()) return it->second; + const char *port = NULL; + user_scheme_port_mutex_.lock(); const auto it2 = user_scheme_port_.find(scheme); if (it2 != user_scheme_port_.end()) - return it2->second.c_str(); + port = it2->second.c_str(); - return NULL; + user_scheme_port_mutex_.unlock(); + return port; } void register_scheme_port(const std::string& scheme, unsigned short port)