Skip to content

Commit

Permalink
Merge pull request free5gc#116 from ShouheiNishi/fix/issue587
Browse files Browse the repository at this point in the history
Add nil check for httpResponse in SendConvergedChargingRequest
  • Loading branch information
ianchen0119 authored Aug 7, 2024
2 parents 65bc752 + 0ca2c22 commit db0b9a7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/sbi/consumer/chf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ func (s *nchfService) SendConvergedChargingRequest(
switch requestType {
case smf_context.CHARGING_INIT:
rsp, httpResponse, err = client.DefaultApi.ChargingdataPost(ctx, *req)
chargingDataRef := strings.Split(httpResponse.Header.Get("Location"), "/")
smContext.ChargingDataRef = chargingDataRef[len(chargingDataRef)-1]
if httpResponse != nil {
chargingDataRef := strings.Split(httpResponse.Header.Get("Location"), "/")
smContext.ChargingDataRef = chargingDataRef[len(chargingDataRef)-1]
}
case smf_context.CHARGING_UPDATE:
rsp, httpResponse, err = client.DefaultApi.ChargingdataChargingDataRefUpdatePost(
ctx, smContext.ChargingDataRef, *req)
Expand All @@ -155,8 +157,10 @@ func (s *nchfService) SendConvergedChargingRequest(
}

defer func() {
if resCloseErr := httpResponse.Body.Close(); resCloseErr != nil {
logger.ChargingLog.Errorf("RegisterNFInstance response body cannot close: %+v", resCloseErr)
if httpResponse != nil {
if resCloseErr := httpResponse.Body.Close(); resCloseErr != nil {
logger.ChargingLog.Errorf("RegisterNFInstance response body cannot close: %+v", resCloseErr)
}
}
}()

Expand Down

0 comments on commit db0b9a7

Please sign in to comment.