pico
created pr with
92.1
cmds
checkout latest patchset:
ssh pr.pico.sh print 92 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 92.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 92
Patchset
92.1
fix(pgs): memory leaks
Eric Bower
2025-12-16T04:01:27ZAll changes replace defer with immediate Close() calls to ensure resources are released promptly rather than accumulating until function return.
Semantic diff summary
0 added,
1 modified,
0 signature changed,
0 removed
across 1 analyzed file
+5
-9
pkg/apps/pgs/web_asset_handler.go
#
| ... | ... | @@ -51,10 +51,8 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 51 | 51 | logger.Info("_redirects not found in lru cache", "key", redirectsCacheKey) | |
| 52 | 52 | redirectFp, redirectInfo, err := h.Cfg.Storage.GetObject(h.Bucket, filepath.Join(h.ProjectDir, "_redirects")) | |
| 53 | 53 | if err == nil { | |
| 54 | - | defer func() { | |
| 55 | - | _ = redirectFp.Close() | |
| 56 | - | }() | |
| 57 | 54 | if redirectInfo != nil && redirectInfo.Size > h.Cfg.MaxSpecialFileSize { | |
| 55 | + | _ = redirectFp.Close() | |
| 58 | 56 | errMsg := fmt.Sprintf("_redirects file is too large (%d > %d)", redirectInfo.Size, h.Cfg.MaxSpecialFileSize) | |
| 59 | 57 | logger.Error(errMsg) | |
| 60 | 58 | http.Error(w, errMsg, http.StatusInternalServerError) |
| ... | ... | @@ -63,6 +61,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 63 | 61 | buf := new(strings.Builder) | |
| 64 | 62 | lr := io.LimitReader(redirectFp, h.Cfg.MaxSpecialFileSize) | |
| 65 | 63 | _, err := io.Copy(buf, lr) | |
| 64 | + | _ = redirectFp.Close() | |
| 66 | 65 | if err != nil { | |
| 67 | 66 | logger.Error("io copy", "err", err.Error()) | |
| 68 | 67 | http.Error(w, "cannot read _redirects file", http.StatusInternalServerError) |
| ... | ... | @@ -219,10 +216,8 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 219 | 216 | logger.Info("_headers not found in lru cache", "key", headersCacheKey) | |
| 220 | 217 | headersFp, headersInfo, err := h.Cfg.Storage.GetObject(h.Bucket, filepath.Join(h.ProjectDir, "_headers")) | |
| 221 | 218 | if err == nil { | |
| 222 | - | defer func() { | |
| 223 | - | _ = headersFp.Close() | |
| 224 | - | }() | |
| 225 | 219 | if headersInfo != nil && headersInfo.Size > h.Cfg.MaxSpecialFileSize { | |
| 220 | + | _ = headersFp.Close() | |
| 226 | 221 | errMsg := fmt.Sprintf("_headers file is too large (%d > %d)", headersInfo.Size, h.Cfg.MaxSpecialFileSize) | |
| 227 | 222 | logger.Error(errMsg) | |
| 228 | 223 | http.Error(w, errMsg, http.StatusInternalServerError) |
| ... | ... | @@ -231,6 +226,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 231 | 226 | buf := new(strings.Builder) | |
| 232 | 227 | lr := io.LimitReader(headersFp, h.Cfg.MaxSpecialFileSize) | |
| 233 | 228 | _, err := io.Copy(buf, lr) | |
| 229 | + | _ = headersFp.Close() | |
| 234 | 230 | if err != nil { | |
| 235 | 231 | logger.Error("io copy", "err", err.Error()) | |
| 236 | 232 | http.Error(w, "cannot read _headers file", http.StatusInternalServerError) |