syncbase: Fix memory leak in ReadBatchFromLog
ReadBatchFromLog iterates through a stream. In the event that it stops
Advancing before the stream is done, we must call stream.Cancel(),
otherwise the stream is never closed.
Change-Id: I386dfdad49ddf84407f1ca09564011bf0afd1120
diff --git a/services/syncbase/store/watchable/watcher.go b/services/syncbase/store/watchable/watcher.go
index bb6d350..a474e8a 100644
--- a/services/syncbase/store/watchable/watcher.go
+++ b/services/syncbase/store/watchable/watcher.go
@@ -178,6 +178,7 @@
seq++
var logEnt LogEntry
if err := vom.Decode(stream.Value(nil), &logEnt); err != nil {
+ stream.Cancel()
return nil, resumeMarker, err
}
@@ -186,14 +187,15 @@
// Stop if this is the end of the batch.
if logEnt.Continued == false {
endOfBatch = true
+ stream.Cancel()
break
}
}
- if err = stream.Err(); err != nil {
- return nil, resumeMarker, err
- }
if !endOfBatch {
+ if err = stream.Err(); err != nil {
+ return nil, resumeMarker, err
+ }
if len(logs) > 0 {
vlog.Fatalf("end of batch not found after %d entries", len(logs))
}