@@ -175,15 +175,17 @@ func (b *Bucket) CreateBucket(key []byte) (*Bucket, error) {
175
175
var value = bucket .write ()
176
176
177
177
// Insert into node.
178
- key = cloneBytes (key )
179
- c .node ().put (key , key , value , 0 , common .BucketLeafFlag )
178
+ // Using new variable here is important: otherwise `key` param
179
+ // is marked as leaking and cannot be allocated on stack.
180
+ newKey := cloneBytes (key )
181
+ c .node ().put (newKey , newKey , value , 0 , common .BucketLeafFlag )
180
182
181
183
// Since subbuckets are not allowed on inline buckets, we need to
182
184
// dereference the inline page, if it exists. This will cause the bucket
183
185
// to be treated as a regular, non-inline bucket for the rest of the tx.
184
186
b .page = nil
185
187
186
- return b .Bucket (key ), nil
188
+ return b .Bucket (newKey ), nil
187
189
}
188
190
189
191
// CreateBucketIfNotExists creates a new bucket if it doesn't already exist and returns a reference to it.
@@ -291,8 +293,10 @@ func (b *Bucket) Put(key []byte, value []byte) error {
291
293
}
292
294
293
295
// Insert into node.
294
- key = cloneBytes (key )
295
- c .node ().put (key , key , value , 0 , 0 )
296
+ // Using new variable here is important: otherwise `key` param
297
+ // is marked as leaking and cannot be allocated on stack.
298
+ newKey := cloneBytes (key )
299
+ c .node ().put (newKey , newKey , value , 0 , 0 )
296
300
297
301
return nil
298
302
}
0 commit comments