mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
tdb: Use tdb_storev in tdb_append
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
parent
504b04b817
commit
c27c7d44fb
@ -699,7 +699,7 @@ _PUBLIC_ int tdb_storev(struct tdb_context *tdb, TDB_DATA key,
|
||||
_PUBLIC_ int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)
|
||||
{
|
||||
uint32_t hash;
|
||||
TDB_DATA dbuf;
|
||||
TDB_DATA dbufs[2];
|
||||
int ret = -1;
|
||||
|
||||
/* find which hash bucket it is in */
|
||||
@ -707,38 +707,14 @@ _PUBLIC_ int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf
|
||||
if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
|
||||
return -1;
|
||||
|
||||
dbuf = _tdb_fetch(tdb, key);
|
||||
dbufs[0] = _tdb_fetch(tdb, key);
|
||||
dbufs[1] = new_dbuf;
|
||||
|
||||
if (dbuf.dptr == NULL) {
|
||||
dbuf.dptr = (unsigned char *)malloc(new_dbuf.dsize);
|
||||
} else {
|
||||
unsigned int new_len = dbuf.dsize + new_dbuf.dsize;
|
||||
unsigned char *new_dptr;
|
||||
ret = _tdb_storev(tdb, key, dbufs, 2, 0, hash);
|
||||
tdb_trace_2rec_retrec(tdb, "tdb_append", key, dbufs[0], dbufs[1]);
|
||||
|
||||
/* realloc '0' is special: don't do that. */
|
||||
if (new_len == 0)
|
||||
new_len = 1;
|
||||
new_dptr = (unsigned char *)realloc(dbuf.dptr, new_len);
|
||||
if (new_dptr == NULL) {
|
||||
free(dbuf.dptr);
|
||||
}
|
||||
dbuf.dptr = new_dptr;
|
||||
}
|
||||
|
||||
if (dbuf.dptr == NULL) {
|
||||
tdb->ecode = TDB_ERR_OOM;
|
||||
goto failed;
|
||||
}
|
||||
|
||||
memcpy(dbuf.dptr + dbuf.dsize, new_dbuf.dptr, new_dbuf.dsize);
|
||||
dbuf.dsize += new_dbuf.dsize;
|
||||
|
||||
ret = _tdb_store(tdb, key, dbuf, 0, hash);
|
||||
tdb_trace_2rec_retrec(tdb, "tdb_append", key, new_dbuf, dbuf);
|
||||
|
||||
failed:
|
||||
tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
|
||||
SAFE_FREE(dbuf.dptr);
|
||||
SAFE_FREE(dbufs[0].dptr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user