aboutsummaryrefslogtreecommitdiff
path: root/bucket.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-04-29 09:34:38 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-04-29 09:34:38 -0600
commit0dfb71267c965e464d6d633a7889c23fb31f722e (patch)
tree308b9c2628968b67c81711c85e9aa7a11c82e6eb /bucket.go
parentMerge pull request #142 from extemporalgenome/Printf-byteslice (diff)
parentCopy key on Put() and CreateBucket(). (diff)
downloaddedo-0dfb71267c965e464d6d633a7889c23fb31f722e.tar.gz
dedo-0dfb71267c965e464d6d633a7889c23fb31f722e.tar.xz
Merge pull request #144 from benbjohnson/copy-key
Copy key on Put() and CreateBucket().
Diffstat (limited to 'bucket.go')
-rw-r--r--bucket.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/bucket.go b/bucket.go
index 571cae4..9737128 100644
--- a/bucket.go
+++ b/bucket.go
@@ -154,6 +154,7 @@ func (b *Bucket) CreateBucket(key []byte) (*Bucket, error) {
bucket.root = p.id
// Insert into node.
+ key = cloneBytes(key)
c.node().put(key, key, value, 0, bucketLeafFlag)
return b.Bucket(key), nil
@@ -262,6 +263,7 @@ func (b *Bucket) Put(key []byte, value []byte) error {
}
// Insert into node.
+ key = cloneBytes(key)
c.node().put(key, key, value, 0, 0)
return nil
@@ -533,3 +535,10 @@ type BucketStats struct {
LeafAlloc int // bytes allocated for physical leaf pages
LeafInuse int // bytes actually used for leaf data
}
+
+// cloneBytes returns a copy of a given slice.
+func cloneBytes(v []byte) []byte {
+ var clone = make([]byte, len(v))
+ copy(clone, v)
+ return clone
+}