[VOL-5421] - fix for crash during ChildDeviceLost

Change-Id: I4cbc4367ad829ec69b5928026789bb48044348f3
Signed-off-by: Sridhar Ravindra <sridhar.ravindra@radisys.com>
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index 3ded77b..98ea868 100755
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -3165,6 +3165,12 @@
 			log.Fields{"parent-device-id": dh.device.Id, "pon-port": pPortNo, "onuID": onuID, "onuSN": onuSn})
 		return nil
 	}
+
+	if dh.transitionMap.currentDeviceState != deviceStateUp {
+		logger.Warnw(ctx, "device-is-not-up--not-handling-child-device-lost", log.Fields{"device-id": dh.device.Id, "current-device-state": dh.transitionMap.currentDeviceState})
+		return fmt.Errorf("device-is-not-up--not-handling-child-device-lost")
+	}
+
 	intfID := plt.PortNoToIntfID(pPortNo, voltha.Port_PON_OLT)
 	onuKey := dh.formOnuKey(intfID, onuID)
 
diff --git a/internal/pkg/resourcemanager/resourcemanager.go b/internal/pkg/resourcemanager/resourcemanager.go
index 3fde9e0..b8053f4 100755
--- a/internal/pkg/resourcemanager/resourcemanager.go
+++ b/internal/pkg/resourcemanager/resourcemanager.go
@@ -577,6 +577,11 @@
 
 	intfOnuIDuniID := fmt.Sprintf("%d,%d,%d", rsrcMgr.PonIntfID, onuID, uniID)
 
+	if rsrcMgr.PonRsrMgr == nil || rsrcMgr.TechprofileRef == nil {
+		logger.Warn(ctx, "PonRsrMgr or TechprofileRef is nil")
+		return
+	}
+
 	AllocIDs := rsrcMgr.PonRsrMgr.GetCurrentAllocIDForOnu(ctx, intfOnuIDuniID)
 
 	if err := rsrcMgr.TechprofileRef.FreeResourceID(ctx, rsrcMgr.PonIntfID,