Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

fix: #1249 invalid memory issue

Matthew Kilgore6a701af0b9a9
diff --git a/backend/app/api/handlers/v1/v1_ctrl_product_search.go b/backend/app/api/handlers/v1/v1_ctrl_product_search.go
index 248cf87e..10c180a5 100644
--- a/backend/app/api/handlers/v1/v1_ctrl_product_search.go
+++ b/backend/app/api/handlers/v1/v1_ctrl_product_search.go
@@ -273,9 +273,13 @@ func (ctrl *V1Controller) HandleProductSearchFromBarcode(conf config.BarcodeAPIC
res, err := client.Get(p.ImageURL)
if err != nil {
log.Warn().Msg("Cannot fetch image for URL: " + p.ImageURL + ": " + err.Error())
+ // On error, res may be nil; skip to next product to avoid nil dereference
+ continue
}
+ // Ensure body is closed for successful responses
defer func() {
+ // res is non-nil here; merge any close error
err = errors.Join(err, res.Body.Close())
}()