Skip to content

Commit c252ec0

Browse files
committed
Add test for deferred close that returns error
1 parent e05bce9 commit c252ec0

File tree

2 files changed

+55
-46
lines changed

2 files changed

+55
-46
lines changed
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
edges
22
| tests.go:9:2:9:74 | ... := ...[0] : pointer type | tests.go:10:9:10:9 | f : pointer type |
3-
| tests.go:10:9:10:9 | f : pointer type | tests.go:34:5:34:38 | ... := ...[0] : pointer type |
4-
| tests.go:10:9:10:9 | f : pointer type | tests.go:51:5:51:38 | ... := ...[0] : pointer type |
5-
| tests.go:10:9:10:9 | f : pointer type | tests.go:77:5:77:38 | ... := ...[0] : pointer type |
6-
| tests.go:10:9:10:9 | f : pointer type | tests.go:87:5:87:38 | ... := ...[0] : pointer type |
7-
| tests.go:10:9:10:9 | f : pointer type | tests.go:99:5:99:38 | ... := ...[0] : pointer type |
8-
| tests.go:10:9:10:9 | f : pointer type | tests.go:115:5:115:38 | ... := ...[0] : pointer type |
9-
| tests.go:18:2:18:69 | return statement[0] : pointer type | tests.go:44:5:44:42 | ... := ...[0] : pointer type |
10-
| tests.go:18:2:18:69 | return statement[0] : pointer type | tests.go:61:5:61:42 | ... := ...[0] : pointer type |
3+
| tests.go:10:9:10:9 | f : pointer type | tests.go:43:5:43:38 | ... := ...[0] : pointer type |
4+
| tests.go:10:9:10:9 | f : pointer type | tests.go:60:5:60:38 | ... := ...[0] : pointer type |
5+
| tests.go:10:9:10:9 | f : pointer type | tests.go:86:5:86:38 | ... := ...[0] : pointer type |
6+
| tests.go:10:9:10:9 | f : pointer type | tests.go:96:5:96:38 | ... := ...[0] : pointer type |
7+
| tests.go:10:9:10:9 | f : pointer type | tests.go:108:5:108:38 | ... := ...[0] : pointer type |
8+
| tests.go:10:9:10:9 | f : pointer type | tests.go:124:5:124:38 | ... := ...[0] : pointer type |
9+
| tests.go:18:2:18:69 | return statement[0] : pointer type | tests.go:53:5:53:42 | ... := ...[0] : pointer type |
10+
| tests.go:18:2:18:69 | return statement[0] : pointer type | tests.go:70:5:70:42 | ... := ...[0] : pointer type |
1111
| tests.go:21:24:21:24 | definition of f : pointer type | tests.go:22:8:22:8 | f |
1212
| tests.go:25:32:25:32 | definition of f : pointer type | tests.go:26:13:26:13 | capture variable f : pointer type |
1313
| tests.go:26:13:26:13 | capture variable f : pointer type | tests.go:27:3:27:3 | f |
14-
| tests.go:34:5:34:38 | ... := ...[0] : pointer type | tests.go:35:21:35:21 | f : pointer type |
15-
| tests.go:34:5:34:38 | ... := ...[0] : pointer type | tests.go:36:29:36:29 | f : pointer type |
16-
| tests.go:35:21:35:21 | f : pointer type | tests.go:21:24:21:24 | definition of f : pointer type |
17-
| tests.go:36:29:36:29 | f : pointer type | tests.go:25:32:25:32 | definition of f : pointer type |
18-
| tests.go:44:5:44:42 | ... := ...[0] : pointer type | tests.go:45:21:45:21 | f : pointer type |
19-
| tests.go:44:5:44:42 | ... := ...[0] : pointer type | tests.go:46:29:46:29 | f : pointer type |
20-
| tests.go:45:21:45:21 | f : pointer type | tests.go:21:24:21:24 | definition of f : pointer type |
21-
| tests.go:46:29:46:29 | f : pointer type | tests.go:25:32:25:32 | definition of f : pointer type |
22-
| tests.go:51:5:51:38 | ... := ...[0] : pointer type | tests.go:53:3:53:3 | f |
23-
| tests.go:61:5:61:42 | ... := ...[0] : pointer type | tests.go:63:3:63:3 | f |
24-
| tests.go:77:5:77:38 | ... := ...[0] : pointer type | tests.go:80:4:80:4 | f |
25-
| tests.go:77:5:77:38 | ... := ...[0] : pointer type | tests.go:82:3:82:3 | f |
26-
| tests.go:87:5:87:38 | ... := ...[0] : pointer type | tests.go:90:9:90:9 | f |
27-
| tests.go:99:5:99:38 | ... := ...[0] : pointer type | tests.go:101:9:101:9 | f |
28-
| tests.go:115:5:115:38 | ... := ...[0] : pointer type | tests.go:119:3:119:3 | f |
14+
| tests.go:43:5:43:38 | ... := ...[0] : pointer type | tests.go:44:21:44:21 | f : pointer type |
15+
| tests.go:43:5:43:38 | ... := ...[0] : pointer type | tests.go:45:29:45:29 | f : pointer type |
16+
| tests.go:44:21:44:21 | f : pointer type | tests.go:21:24:21:24 | definition of f : pointer type |
17+
| tests.go:45:29:45:29 | f : pointer type | tests.go:25:32:25:32 | definition of f : pointer type |
18+
| tests.go:53:5:53:42 | ... := ...[0] : pointer type | tests.go:54:21:54:21 | f : pointer type |
19+
| tests.go:53:5:53:42 | ... := ...[0] : pointer type | tests.go:55:29:55:29 | f : pointer type |
20+
| tests.go:54:21:54:21 | f : pointer type | tests.go:21:24:21:24 | definition of f : pointer type |
21+
| tests.go:55:29:55:29 | f : pointer type | tests.go:25:32:25:32 | definition of f : pointer type |
22+
| tests.go:60:5:60:38 | ... := ...[0] : pointer type | tests.go:62:3:62:3 | f |
23+
| tests.go:70:5:70:42 | ... := ...[0] : pointer type | tests.go:72:3:72:3 | f |
24+
| tests.go:86:5:86:38 | ... := ...[0] : pointer type | tests.go:89:4:89:4 | f |
25+
| tests.go:86:5:86:38 | ... := ...[0] : pointer type | tests.go:91:3:91:3 | f |
26+
| tests.go:96:5:96:38 | ... := ...[0] : pointer type | tests.go:99:9:99:9 | f |
27+
| tests.go:108:5:108:38 | ... := ...[0] : pointer type | tests.go:110:9:110:9 | f |
28+
| tests.go:124:5:124:38 | ... := ...[0] : pointer type | tests.go:128:3:128:3 | f |
2929
nodes
3030
| tests.go:9:2:9:74 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
3131
| tests.go:10:9:10:9 | f : pointer type | semmle.label | f : pointer type |
@@ -35,32 +35,32 @@ nodes
3535
| tests.go:25:32:25:32 | definition of f : pointer type | semmle.label | definition of f : pointer type |
3636
| tests.go:26:13:26:13 | capture variable f : pointer type | semmle.label | capture variable f : pointer type |
3737
| tests.go:27:3:27:3 | f | semmle.label | f |
38-
| tests.go:34:5:34:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
39-
| tests.go:35:21:35:21 | f : pointer type | semmle.label | f : pointer type |
40-
| tests.go:36:29:36:29 | f : pointer type | semmle.label | f : pointer type |
41-
| tests.go:44:5:44:42 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
42-
| tests.go:45:21:45:21 | f : pointer type | semmle.label | f : pointer type |
43-
| tests.go:46:29:46:29 | f : pointer type | semmle.label | f : pointer type |
44-
| tests.go:51:5:51:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
45-
| tests.go:53:3:53:3 | f | semmle.label | f |
46-
| tests.go:61:5:61:42 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
47-
| tests.go:63:3:63:3 | f | semmle.label | f |
48-
| tests.go:77:5:77:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
49-
| tests.go:80:4:80:4 | f | semmle.label | f |
50-
| tests.go:82:3:82:3 | f | semmle.label | f |
51-
| tests.go:87:5:87:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
52-
| tests.go:90:9:90:9 | f | semmle.label | f |
53-
| tests.go:99:5:99:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
54-
| tests.go:101:9:101:9 | f | semmle.label | f |
55-
| tests.go:115:5:115:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
56-
| tests.go:119:3:119:3 | f | semmle.label | f |
38+
| tests.go:43:5:43:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
39+
| tests.go:44:21:44:21 | f : pointer type | semmle.label | f : pointer type |
40+
| tests.go:45:29:45:29 | f : pointer type | semmle.label | f : pointer type |
41+
| tests.go:53:5:53:42 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
42+
| tests.go:54:21:54:21 | f : pointer type | semmle.label | f : pointer type |
43+
| tests.go:55:29:55:29 | f : pointer type | semmle.label | f : pointer type |
44+
| tests.go:60:5:60:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
45+
| tests.go:62:3:62:3 | f | semmle.label | f |
46+
| tests.go:70:5:70:42 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
47+
| tests.go:72:3:72:3 | f | semmle.label | f |
48+
| tests.go:86:5:86:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
49+
| tests.go:89:4:89:4 | f | semmle.label | f |
50+
| tests.go:91:3:91:3 | f | semmle.label | f |
51+
| tests.go:96:5:96:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
52+
| tests.go:99:9:99:9 | f | semmle.label | f |
53+
| tests.go:108:5:108:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
54+
| tests.go:110:9:110:9 | f | semmle.label | f |
55+
| tests.go:124:5:124:38 | ... := ...[0] : pointer type | semmle.label | ... := ...[0] : pointer type |
56+
| tests.go:128:3:128:3 | f | semmle.label | f |
5757
subpaths
5858
#select
5959
| tests.go:22:8:22:8 | f | tests.go:9:2:9:74 | ... := ...[0] : pointer type | tests.go:22:8:22:8 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:9:12:9:74 | call to OpenFile | call to OpenFile |
6060
| tests.go:22:8:22:8 | f | tests.go:18:2:18:69 | return statement[0] : pointer type | tests.go:22:8:22:8 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:18:9:18:69 | call to OpenFile | call to OpenFile |
6161
| tests.go:27:3:27:3 | f | tests.go:9:2:9:74 | ... := ...[0] : pointer type | tests.go:27:3:27:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:9:12:9:74 | call to OpenFile | call to OpenFile |
6262
| tests.go:27:3:27:3 | f | tests.go:18:2:18:69 | return statement[0] : pointer type | tests.go:27:3:27:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:18:9:18:69 | call to OpenFile | call to OpenFile |
63-
| tests.go:53:3:53:3 | f | tests.go:9:2:9:74 | ... := ...[0] : pointer type | tests.go:53:3:53:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:9:12:9:74 | call to OpenFile | call to OpenFile |
64-
| tests.go:63:3:63:3 | f | tests.go:18:2:18:69 | return statement[0] : pointer type | tests.go:63:3:63:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:18:9:18:69 | call to OpenFile | call to OpenFile |
65-
| tests.go:101:9:101:9 | f | tests.go:9:2:9:74 | ... := ...[0] : pointer type | tests.go:101:9:101:9 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:9:12:9:74 | call to OpenFile | call to OpenFile |
66-
| tests.go:119:3:119:3 | f | tests.go:9:2:9:74 | ... := ...[0] : pointer type | tests.go:119:3:119:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:9:12:9:74 | call to OpenFile | call to OpenFile |
63+
| tests.go:62:3:62:3 | f | tests.go:9:2:9:74 | ... := ...[0] : pointer type | tests.go:62:3:62:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:9:12:9:74 | call to OpenFile | call to OpenFile |
64+
| tests.go:72:3:72:3 | f | tests.go:18:2:18:69 | return statement[0] : pointer type | tests.go:72:3:72:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:18:9:18:69 | call to OpenFile | call to OpenFile |
65+
| tests.go:110:9:110:9 | f | tests.go:9:2:9:74 | ... := ...[0] : pointer type | tests.go:110:9:110:9 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:9:12:9:74 | call to OpenFile | call to OpenFile |
66+
| tests.go:128:3:128:3 | f | tests.go:9:2:9:74 | ... := ...[0] : pointer type | tests.go:128:3:128:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:9:12:9:74 | call to OpenFile | call to OpenFile |

go/ql/test/query-tests/InconsistentCode/UnhandledCloseWritableHandle/tests.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ func closeFileDeferredIndirect(f *os.File) {
3030
defer cont()
3131
}
3232

33+
func closeFileDeferredIndirectReturn(f *os.File) {
34+
var cont = func() error {
35+
return f.Close() // OK, because this function returns the error
36+
}
37+
38+
// different (more general) problem: deferred error
39+
defer cont()
40+
}
41+
3342
func deferredCalls() {
3443
if f, err := openFileWrite("foo.txt"); err != nil {
3544
closeFileDeferred(f) // NOT OK

0 commit comments

Comments
 (0)