@@ -154,12 +154,17 @@ func (b *Bucket) CreateBucket(key []byte) (*Bucket, error) {
154
154
return nil , errors .ErrBucketNameRequired
155
155
}
156
156
157
+ // Insert into node.
158
+ // Tip: Use a new variable `newKey` instead of reusing the existing `key` to prevent
159
+ // it from being marked as leaking, and accordingly cannot be allocated on stack.
160
+ newKey := cloneBytes (key )
161
+
157
162
// Move cursor to correct position.
158
163
c := b .Cursor ()
159
- k , _ , flags := c .seek (key )
164
+ k , _ , flags := c .seek (newKey )
160
165
161
166
// Return an error if there is an existing key.
162
- if bytes .Equal (key , k ) {
167
+ if bytes .Equal (newKey , k ) {
163
168
if (flags & common .BucketLeafFlag ) != 0 {
164
169
return nil , errors .ErrBucketExists
165
170
}
@@ -174,10 +179,6 @@ func (b *Bucket) CreateBucket(key []byte) (*Bucket, error) {
174
179
}
175
180
var value = bucket .write ()
176
181
177
- // Insert into node.
178
- // Tip: Use a new variable `newKey` instead of reusing the existing `key` to prevent
179
- // it from being marked as leaking, and accordingly cannot be allocated on stack.
180
- newKey := cloneBytes (key )
181
182
c .node ().put (newKey , newKey , value , 0 , common .BucketLeafFlag )
182
183
183
184
// Since subbuckets are not allowed on inline buckets, we need to
0 commit comments