Use finalizers to detect unclosed connections.

This commit is contained in:
Nuno Cruces
2023-03-03 13:15:24 +00:00
parent 416c3863a0
commit 35b1a97b88
5 changed files with 27 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package sqlite3
import (
"fmt"
"runtime"
"strconv"
"strings"
@@ -215,3 +216,11 @@ func assertErr() errorString {
}
return errorString(msg)
}
func finalizer[T any](skip int) func(*T) {
msg := fmt.Sprintf("sqlite3: %T not closed", new(T))
if _, file, line, ok := runtime.Caller(skip + 1); ok && skip >= 0 {
msg += " (" + file + ":" + strconv.Itoa(line) + ")"
}
return func(*T) { panic(errorString(msg)) }
}