aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-01-15 16:26:28 +0100
committerGitHub <noreply@github.com>2018-01-15 16:26:28 +0100
commit861e3996c09e960bfa64ec1c4141b23f6072ccee (patch)
treee1d85219c10892c7e4ace92614607d23ac0d522b
parent2547d1d9aa16b7c93b677bb63d8b8daea55d7e86 (diff)
parent39292679f27a44e03eede16578e5e6bf82fb9e20 (diff)
downloadgo-git-861e3996c09e960bfa64ec1c4141b23f6072ccee.tar.gz
Merge pull request #716 from jfontan/fix/memory-leak-packing-objects
Clean reconstructed objects outside pack window
-rw-r--r--plumbing/format/packfile/delta_selector.go32
1 files changed, 19 insertions, 13 deletions
diff --git a/plumbing/format/packfile/delta_selector.go b/plumbing/format/packfile/delta_selector.go
index 8792574..cd38c16 100644
--- a/plumbing/format/packfile/delta_selector.go
+++ b/plumbing/format/packfile/delta_selector.go
@@ -222,10 +222,16 @@ func (dw *deltaSelector) walk(
) error {
indexMap := make(map[plumbing.Hash]*deltaIndex)
for i := 0; i < len(objectsToPack); i++ {
- // Clean up the index map for anything outside our pack
- // window, to save memory.
+ // Clean up the index map and reconstructed delta objects for anything
+ // outside our pack window, to save memory.
if i > int(packWindow) {
- delete(indexMap, objectsToPack[i-int(packWindow)].Hash())
+ obj := objectsToPack[i-int(packWindow)]
+
+ delete(indexMap, obj.Hash())
+
+ if obj.IsDelta() {
+ obj.Original = nil
+ }
}
target := objectsToPack[i]
@@ -261,6 +267,16 @@ func (dw *deltaSelector) walk(
}
func (dw *deltaSelector) tryToDeltify(indexMap map[plumbing.Hash]*deltaIndex, base, target *ObjectToPack) error {
+ // Original object might not be present if we're reusing a delta, so we
+ // ensure it is restored.
+ if err := dw.restoreOriginal(target); err != nil {
+ return err
+ }
+
+ if err := dw.restoreOriginal(base); err != nil {
+ return err
+ }
+
// If the sizes are radically different, this is a bad pairing.
if target.Size() < base.Size()>>4 {
return nil
@@ -283,16 +299,6 @@ func (dw *deltaSelector) tryToDeltify(indexMap map[plumbing.Hash]*deltaIndex, ba
return nil
}
- // Original object might not be present if we're reusing a delta, so we
- // ensure it is restored.
- if err := dw.restoreOriginal(target); err != nil {
- return err
- }
-
- if err := dw.restoreOriginal(base); err != nil {
- return err
- }
-
if _, ok := indexMap[base.Hash()]; !ok {
indexMap[base.Hash()] = new(deltaIndex)
}