Commit 3d99453
authored
backport(v0.41.2): mdbx: bar copying Cursor and Txn with noCopy (#251)
* mdbx: bar copying a Cursor with noCopy
A Cursor owns a raw libmdbx cursor, so copying the struct hands two values one
underlying cursor: Close on either frees it while the other still points at it,
and the second Close is a double free into cgo. Nothing caught that — the
struct holds no sync type, so copylocks had nothing to key on. Embedding a
Cursor by value, which Open exists for, is unaffected.
Zero-sized and placed first, so sizeof(Cursor) is unchanged at 16 bytes.
(cherry picked from commit daf9fff)
* mdbx: extend noCopy to Txn, move it to its own file
Txn owns a raw libmdbx transaction, so a copy hands two values one txn and
Abort/Commit on either leaves the other dangling — the same hazard as Cursor.
Env needs nothing: its closeLock already makes copylocks reject copies.
noCopy moves to nocopy.go so it sits between neither type and its doc comment.
(cherry picked from commit a29acaf)1 parent afa609b commit 3d99453
4 files changed
Lines changed: 34 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
| |||
0 commit comments