Skip to content

Commit

Permalink
minor code cleanup
Browse files Browse the repository at this point in the history
fixed possible memory leak
  • Loading branch information
djcass44 committed May 7, 2024
1 parent 3f734f5 commit 19a74f6
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 86 deletions.
4 changes: 2 additions & 2 deletions pkg/containerutil/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

func Save(ctx context.Context, img v1.Image, dst, path string) error {
log := logr.FromContextOrDiscard(ctx)
log.Info("saving image to local file", "path", path)
log := logr.FromContextOrDiscard(ctx).WithValues("path", path, "dst", dst)
log.Info("saving image to local file")
if err := crane.Save(img, dst, path); err != nil {
log.Error(err, "failed to save image")
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/lockfile/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Read(ctx context.Context, cfgPath string) (*Lock, error) {
log.Error(err, "failed to open lockfile")
return nil, err
}
defer lock.Close()
// read the lockfile
var lockFile Lock
if err := json.NewDecoder(lock).Decode(&lockFile); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/lockfile/sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"encoding/hex"
"io"
"os"
"path/filepath"
)

func Sha256(path string) (string, error) {
f, err := os.Open(path)
f, err := os.Open(filepath.Clean(path))
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/yum/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/go-getter"
"net/http"
"os"
"path/filepath"
"strings"
)

Expand Down Expand Up @@ -42,7 +43,7 @@ func NewIndex(ctx context.Context, repository string) (*yumindex.Metadata, error
if err := client.Get(); err != nil {
return nil, fmt.Errorf("downloading primary index: %w", err)
}
f, err := os.Open(dst)
f, err := os.Open(filepath.Clean(dst))
if err != nil {
return nil, fmt.Errorf("opening index: %w", err)
}
Expand Down
Loading

0 comments on commit 19a74f6

Please sign in to comment.