Skip to content
8 changes: 6 additions & 2 deletions modules/git/blob_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"bytes"
"io"
"math"
"runtime"

"code.gitea.io/gitea/modules/log"
)
Expand Down Expand Up @@ -54,11 +55,14 @@ func (b *Blob) DataAsync() (io.ReadCloser, error) {
return io.NopCloser(bytes.NewReader(bs)), err
}

return &blobReader{
br := &blobReader{
rd: rd,
n: size,
cancel: cancel,
}, nil
}
runtime.SetFinalizer(br, func(br *blobReader) { br.Close() })

return br, nil
}

// Size returns the uncompressed size of the blob
Expand Down
9 changes: 7 additions & 2 deletions modules/git/repo_base_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"context"
"errors"
"path/filepath"
"runtime"

gitealog "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
Expand Down Expand Up @@ -63,13 +64,17 @@ func OpenRepositoryCtx(ctx context.Context, repoPath string) (*Repository, error
return nil, err
}

return &Repository{
repo := &Repository{
Path: repoPath,
gogitRepo: gogitRepo,
gogitStorage: storage,
tagCache: newObjectCache(),
Ctx: ctx,
}, nil
}

runtime.SetFinalizer(repo, func(repo *Repository) { repo.Close() })

return repo, nil
}

// Close this repository, in particular close the underlying gogitStorage if this is not nil
Expand Down
3 changes: 3 additions & 0 deletions modules/git/repo_base_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"context"
"errors"
"path/filepath"
"runtime"

"code.gitea.io/gitea/modules/log"
)
Expand Down Expand Up @@ -64,6 +65,8 @@ func OpenRepositoryCtx(ctx context.Context, repoPath string) (*Repository, error
repo.batchWriter, repo.batchReader, repo.batchCancel = CatFileBatch(ctx, repoPath)
repo.checkWriter, repo.checkReader, repo.checkCancel = CatFileBatchCheck(ctx, repo.Path)

runtime.SetFinalizer(repo, func(repo *Repository) { repo.Close() })

return repo, nil
}

Expand Down