Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed dangling pointer using std::string #3112

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libYARP_manager/src/yarp/manager/broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Broker {
const char* carrier) = 0;
virtual int running() = 0; // 0 if is not running and 1 if is running; otherwise -1.
virtual bool exists(const char* port) = 0;
virtual const char* requestRpc(const char* szport, const char* request, double timeout=0.0) = 0;
virtual std::string requestRpc(const char* szport, const char* request, double timeout=0.0) = 0;
virtual bool connected(const char* from, const char* to,
const char* carrier) = 0;
virtual const char* error() = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/libYARP_manager/src/yarp/manager/execstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ bool Ready::checkResources(bool silent)
}
// check the rpc request/reply if required
if(strlen((*itr).getRequest()) != 0) {
const char* reply = executable->getBroker()->requestRpc((*itr).getPort(),
std::string reply = executable->getBroker()->requestRpc((*itr).getPort(),
(*itr).getRequest(),
(*itr).getTimeout());
if(reply == nullptr) {
if(reply.empty()) {
allOK = false;
OSTRINGSTREAM msg;
msg<<"cannot request resource "<<(*itr).getPort()<<" for "<<(*itr).getRequest();
Expand All @@ -142,7 +142,7 @@ bool Ready::checkResources(bool silent)
}
}

if(!compareString(reply, (*itr).getReply())) {
if (!compareString(reply.c_str(), (*itr).getReply())) {
allOK = false;
OSTRINGSTREAM msg;
msg<<"waiting for the expected reply from resource "<<(*itr).getPort();
Expand Down
12 changes: 6 additions & 6 deletions src/libYARP_manager/src/yarp/manager/localbroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,21 +445,21 @@ bool LocalBroker::exists(const char* port)
}


const char* LocalBroker::requestRpc(const char* szport, const char* request, double timeout)
std::string LocalBroker::requestRpc(const char* szport, const char* request, double timeout)
{
if ((szport == nullptr) || (request == nullptr)) {
return nullptr;
return {};
}

if (!exists(szport)) {
return nullptr;
return {};
}

// opening the port
yarp::os::Port port;
port.setTimeout((float)((timeout>0.0) ? timeout : CONNECTION_TIMEOUT));
if (!port.open("...")) {
return nullptr;
return {};
}

ContactStyle style;
Expand All @@ -476,7 +476,7 @@ const char* LocalBroker::requestRpc(const char* szport, const char* request, dou

if(!ret) {
port.close();
return nullptr;
return {};
}

Bottle msg, response;
Expand All @@ -485,7 +485,7 @@ const char* LocalBroker::requestRpc(const char* szport, const char* request, dou
NetworkBase::disconnect(port.getName(), szport);
if(!response.size() || !ret) {
port.close();
return nullptr;
return {};
}

port.close();
Expand Down
2 changes: 1 addition & 1 deletion src/libYARP_manager/src/yarp/manager/localbroker.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class LocalBroker: public Broker, public yarp::os::Thread {
const char *carrier) override;
int running() override;
bool exists(const char* port) override;
const char* requestRpc(const char* szport, const char* request, double timeout) override;
std::string requestRpc(const char* szport, const char* request, double timeout) override;
bool connected(const char* from, const char* to,
const char* carrier) override;
const char* error() override;
Expand Down
12 changes: 6 additions & 6 deletions src/libYARP_manager/src/yarp/manager/yarpbroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,21 +529,21 @@ bool YarpBroker::exists(const char* szport)
return NetworkBase::exists(szport, style);
}

const char* YarpBroker::requestRpc(const char* szport, const char* request, double timeout)
std::string YarpBroker::requestRpc(const char* szport, const char* request, double timeout)
{
if ((szport == nullptr) || (request == nullptr)) {
return nullptr;
return {};
}

if (!exists(szport)) {
return nullptr;
return {};
}

// opening the port
yarp::os::Port port;
port.setTimeout((float)((timeout>0.0) ? timeout : CONNECTION_TIMEOUT));
if (!port.open("...")) {
return nullptr;
return {};
}

ContactStyle style;
Expand All @@ -560,7 +560,7 @@ const char* YarpBroker::requestRpc(const char* szport, const char* request, doub

if(!ret) {
port.close();
return nullptr;
return {};
}

Bottle msg, response;
Expand All @@ -569,7 +569,7 @@ const char* YarpBroker::requestRpc(const char* szport, const char* request, doub
NetworkBase::disconnect(port.getName(), szport);
if(!response.size() || !ret) {
port.close();
return nullptr;
return {};
}

port.close();
Expand Down
2 changes: 1 addition & 1 deletion src/libYARP_manager/src/yarp/manager/yarpbroker.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class YarpBroker: public Broker, public yarp::os::PeriodicThread {
bool rmconnect(const char* from, const char* to);
int running() override;
bool exists(const char* port) override;
const char* requestRpc(const char* szport, const char* request, double timeout) override;
std::string requestRpc(const char* szport, const char* request, double timeout) override;
bool connected(const char* from, const char* to, const char* carrier) override;
const char* error() override;
bool initialized() override { return bInitialized;}
Expand Down
Loading