summaryrefslogtreecommitdiff
path: root/lib/tdb/common
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2011-12-15 10:50:34 +0100
committerVolker Lendecke <vl@samba.org>2011-12-19 15:18:08 +0100
commit664add17757836c5ee98618aef11371f412b6e44 (patch)
tree5e74d3ac0d61ea2618751af9906d08b6967ec8c2 /lib/tdb/common
parentf39426c8ae6dc6a64acbdbe6087f0f0c359a4a96 (diff)
downloadsamba-664add17757836c5ee98618aef11371f412b6e44.tar.gz
samba-664add17757836c5ee98618aef11371f412b6e44.tar.bz2
samba-664add17757836c5ee98618aef11371f412b6e44.zip
tdb: Avoid a malloc/memcpy in _tdb_store
Diffstat (limited to 'lib/tdb/common')
-rw-r--r--lib/tdb/common/tdb.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/lib/tdb/common/tdb.c b/lib/tdb/common/tdb.c
index 3a3c99c553..ac2a482eba 100644
--- a/lib/tdb/common/tdb.c
+++ b/lib/tdb/common/tdb.c
@@ -473,7 +473,6 @@ static int _tdb_store(struct tdb_context *tdb, TDB_DATA key,
{
struct tdb_record rec;
tdb_off_t rec_ptr;
- char *p = NULL;
int ret = -1;
/* check for it existing, on insert. */
@@ -503,18 +502,6 @@ static int _tdb_store(struct tdb_context *tdb, TDB_DATA key,
if (flag != TDB_INSERT)
tdb_delete_hash(tdb, key, hash);
- /* Copy key+value *before* allocating free space in case malloc
- fails and we are left with a dead spot in the tdb. */
-
- if (!(p = (char *)malloc(key.dsize + dbuf.dsize))) {
- tdb->ecode = TDB_ERR_OOM;
- goto fail;
- }
-
- memcpy(p, key.dptr, key.dsize);
- if (dbuf.dsize)
- memcpy(p+key.dsize, dbuf.dptr, dbuf.dsize);
-
if (tdb->max_dead_records != 0) {
/*
* Allow for some dead records per hash chain, look if we can
@@ -534,7 +521,10 @@ static int _tdb_store(struct tdb_context *tdb, TDB_DATA key,
if (tdb_rec_write(tdb, rec_ptr, &rec) == -1
|| tdb->methods->tdb_write(
tdb, rec_ptr + sizeof(rec),
- p, key.dsize + dbuf.dsize) == -1) {
+ key.dptr, key.dsize) == -1
+ || tdb->methods->tdb_write(
+ tdb, rec_ptr + sizeof(rec) + key.dsize,
+ dbuf.dptr, dbuf.dsize) == -1) {
goto fail;
}
goto done;
@@ -577,7 +567,10 @@ static int _tdb_store(struct tdb_context *tdb, TDB_DATA key,
/* write out and point the top of the hash chain at it */
if (tdb_rec_write(tdb, rec_ptr, &rec) == -1
- || tdb->methods->tdb_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+dbuf.dsize)==-1
+ || tdb->methods->tdb_write(tdb, rec_ptr+sizeof(rec),
+ key.dptr, key.dsize) == -1
+ || tdb->methods->tdb_write(tdb, rec_ptr+sizeof(rec)+key.dsize,
+ dbuf.dptr, dbuf.dsize) == -1
|| tdb_ofs_write(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) {
/* Need to tdb_unallocate() here */
goto fail;
@@ -589,8 +582,6 @@ static int _tdb_store(struct tdb_context *tdb, TDB_DATA key,
if (ret == 0) {
tdb_increment_seqnum(tdb);
}
-
- SAFE_FREE(p);
return ret;
}