From 49bc78bc9296d5c4293f3e507c6a3ceb5970cdca Mon Sep 17 00:00:00 2001 From: Ze Gan Date: Wed, 14 Aug 2019 22:32:48 +0800 Subject: [PATCH] [Orchagent]: Fixbug segmentfault at routeorch The log statement will cause segmentfault if `observerEntry->second.routeTable` is empty. Signed-off-by: Ze Gan --- orchagent/routeorch.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 12162a5d94e..a75b321158a 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -156,15 +156,14 @@ void RouteOrch::attach(Observer *observer, const IpAddress& dstAddr) observerEntry->second.observers.push_back(observer); - SWSS_LOG_NOTICE("Attached next hop observer of route %s for destination IP %s", - observerEntry->second.routeTable.rbegin()->first.to_string().c_str(), - dstAddr.to_string().c_str()); - // Trigger next hop change for the first time the observer is attached // Note that rbegin() is pointing to the entry with longest prefix match auto route = observerEntry->second.routeTable.rbegin(); if (route != observerEntry->second.routeTable.rend()) { + SWSS_LOG_NOTICE("Attached next hop observer of route %s for destination IP %s", + observerEntry->second.routeTable.rbegin()->first.to_string().c_str(), + dstAddr.to_string().c_str()); NextHopUpdate update = { dstAddr, route->first, route->second }; observer->update(SUBJECT_TYPE_NEXTHOP_CHANGE, static_cast(&update)); }