Explorar o código

mvcc: check null before set FillPercent not to panic

Since CreateBucketIfNotExists() can return nil when it gets an error,
accessing FillPercent must be done after a nil check, not to cause
a panic.
Iwasaki Yudai %!s(int64=8) %!d(string=hai) anos
pai
achega
6999bbb47b
Modificáronse 1 ficheiros con 1 adicións e 1 borrados
  1. 1 1
      mvcc/backend/backend.go

+ 1 - 1
mvcc/backend/backend.go

@@ -370,10 +370,10 @@ func defragdb(odb, tmpdb *bolt.DB, limit int) error {
 		}
 		}
 
 
 		tmpb, berr := tmptx.CreateBucketIfNotExists(next)
 		tmpb, berr := tmptx.CreateBucketIfNotExists(next)
-		tmpb.FillPercent = 0.9 // for seq write in for each
 		if berr != nil {
 		if berr != nil {
 			return berr
 			return berr
 		}
 		}
+		tmpb.FillPercent = 0.9 // for seq write in for each
 
 
 		b.ForEach(func(k, v []byte) error {
 		b.ForEach(func(k, v []byte) error {
 			count++
 			count++