diff options
author | Volker Lendecke <vl@samba.org> | 2011-12-15 10:50:34 +0100 |
---|---|---|
committer | Volker Lendecke <vlendec@samba.org> | 2011-12-19 16:53:39 +0100 |
commit | bfc74811d04c5fa003f04947e573ee98fc510b13 (patch) | |
tree | 3c8695207c1f434794e692b829a24fc2eee078d0 | |
parent | 664add17757836c5ee98618aef11371f412b6e44 (diff) | |
download | samba-bfc74811d04c5fa003f04947e573ee98fc510b13.tar.gz samba-bfc74811d04c5fa003f04947e573ee98fc510b13.tar.bz2 samba-bfc74811d04c5fa003f04947e573ee98fc510b13.zip |
tdb2: Avoid a malloc/memcpy in _tdb1_store
Autobuild-User: Volker Lendecke <vlendec@samba.org>
Autobuild-Date: Mon Dec 19 16:53:40 CET 2011 on sn-devel-104
-rw-r--r-- | lib/tdb2/tdb1_tdb.c | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/lib/tdb2/tdb1_tdb.c b/lib/tdb2/tdb1_tdb.c index 6f6f080da2..a220f47169 100644 --- a/lib/tdb2/tdb1_tdb.c +++ b/lib/tdb2/tdb1_tdb.c @@ -478,7 +478,6 @@ static int _tdb1_store(struct tdb_context *tdb, TDB_DATA key, { struct tdb1_record rec; tdb1_off_t rec_ptr; - char *p = NULL; int ret = -1; /* check for it existing, on insert. */ @@ -515,20 +514,6 @@ static int _tdb1_store(struct tdb_context *tdb, TDB_DATA key, if (flag != TDB_INSERT) tdb1_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->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR, - "tdb1_store: out of memory" - " allocating copy"); - goto fail; - } - - memcpy(p, key.dptr, key.dsize); - if (dbuf.dsize) - memcpy(p+key.dsize, dbuf.dptr, dbuf.dsize); - if (tdb->tdb1.max_dead_records != 0) { /* * Allow for some dead records per hash chain, look if we can @@ -548,7 +533,10 @@ static int _tdb1_store(struct tdb_context *tdb, TDB_DATA key, if (tdb1_rec_write(tdb, rec_ptr, &rec) == -1 || tdb->tdb1.io->tdb1_write( tdb, rec_ptr + sizeof(rec), - p, key.dsize + dbuf.dsize) == -1) { + key.dptr, key.dsize) == -1 + || tdb->tdb1.io->tdb1_write( + tdb, rec_ptr + sizeof(rec) + key.dsize, + dbuf.dptr, dbuf.dsize) == -1) { goto fail; } goto done; @@ -591,7 +579,10 @@ static int _tdb1_store(struct tdb_context *tdb, TDB_DATA key, /* write out and point the top of the hash chain at it */ if (tdb1_rec_write(tdb, rec_ptr, &rec) == -1 - || tdb->tdb1.io->tdb1_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+dbuf.dsize)==-1 + || tdb->tdb1.io->tdb1_write(tdb, rec_ptr + sizeof(rec), + key.dptr, key.dsize) == -1 + || tdb->tdb1.io->tdb1_write(tdb, rec_ptr + sizeof(rec) + key.dsize, + dbuf.dptr, dbuf.dsize) == -1 || tdb1_ofs_write(tdb, TDB1_HASH_TOP(hash), &rec_ptr) == -1) { /* Need to tdb1_unallocate() here */ goto fail; @@ -603,8 +594,6 @@ static int _tdb1_store(struct tdb_context *tdb, TDB_DATA key, if (ret == 0) { tdb1_increment_seqnum(tdb); } - - SAFE_FREE(p); return ret; } |