mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-25 06:49:18 +01:00
ProductBarcode: backend: fix resource leak with defer
This commit is contained in:
@@ -192,7 +192,6 @@ func (ctrl *V1Controller) HandleProductSearchFromBarcode(conf config.BarcodeAPIC
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("barcodespider API returned status code: %d", resp.StatusCode)
|
return nil, fmt.Errorf("barcodespider API returned status code: %d", resp.StatusCode)
|
||||||
@@ -204,6 +203,8 @@ func (ctrl *V1Controller) HandleProductSearchFromBarcode(conf config.BarcodeAPIC
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resp.Body.Close()
|
||||||
|
|
||||||
// Convert the body to type string
|
// Convert the body to type string
|
||||||
sb := string(body)
|
sb := string(body)
|
||||||
log.Info().Msg("Response: " + sb)
|
log.Info().Msg("Response: " + sb)
|
||||||
@@ -259,15 +260,15 @@ func (ctrl *V1Controller) HandleProductSearchFromBarcode(conf config.BarcodeAPIC
|
|||||||
log.Warn().Msg("Cannot fetch image for URL: " + p.ImageURL + ": " + err.Error())
|
log.Warn().Msg("Cannot fetch image for URL: " + p.ImageURL + ": " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
defer res.Body.Close()
|
|
||||||
|
|
||||||
// Validate response
|
// Validate response
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
|
res.Body.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read data of image
|
// Read data of image
|
||||||
bytes, err := io.ReadAll(res.Body)
|
bytes, err := io.ReadAll(res.Body)
|
||||||
|
res.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Msg(err.Error())
|
log.Warn().Msg(err.Error())
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user