Skip to content

Commit

Permalink
ensure cursor is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
rwynn committed Nov 14, 2019
1 parent 6d019d8 commit 32a9d23
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gtm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,9 @@ func GetCollectionInfo(ctx *OpCtx, client *mongo.Client, ns string) (info *Colle
}
var cursor *mongo.Cursor
cursor, err = client.Database(n.database).ListCollections(context.Background(), bson.M{"name": n.collection})
if err == nil {
if cursor.Next(context.Background()) {
if cursor != nil {
defer cursor.Close(context.Background())
if err == nil && cursor.Next(context.Background()) {
err = cursor.Decode(info)
}
}
Expand Down

0 comments on commit 32a9d23

Please sign in to comment.