Skip to content

Commit de534eb

Browse files
polycubed: remove port when error setting peer
A port is first created and then the peer is configured if needed, if something goes wrong while setting the peer, remove the created port. Signed-off-by: Mauricio Vasquez B <mauriciovasquezbernal@gmail.com>
1 parent ac8edf4 commit de534eb

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/polycubed/src/cube.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,14 @@ std::shared_ptr<PortIface> Cube::add_port(const std::string &name,
117117

118118
// TODO: is this valid?
119119
cube_mutex_.unlock();
120-
121-
if (conf.count("peer")) {
122-
port->set_peer(conf.at("peer").get<std::string>());
120+
try {
121+
if (conf.count("peer")) {
122+
port->set_peer(conf.at("peer").get<std::string>());
123+
}
124+
} catch(...) {
125+
ports_by_name_.erase(name);
126+
ports_by_index_.erase(id);
127+
throw;
123128
}
124129

125130
return std::move(port);

0 commit comments

Comments
 (0)