diff options
author | Jeremy Allison <jra@samba.org> | 2002-09-26 21:00:25 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-09-26 21:00:25 +0000 |
commit | c60f6f066ea47f7d85fc8028f9d657cfe5841893 (patch) | |
tree | 02354922b76d0a2967114b490a72822885d7e101 /source3 | |
parent | 996fc282489434b85366c6d4c0e046e032e47a1a (diff) | |
download | samba-c60f6f066ea47f7d85fc8028f9d657cfe5841893.tar.gz samba-c60f6f066ea47f7d85fc8028f9d657cfe5841893.tar.bz2 samba-c60f6f066ea47f7d85fc8028f9d657cfe5841893.zip |
Make explicit the difference between a tdb key with no data attached, and
a non existent entry. Stop a malloc(0) being called in the first case.
Jeremy.
(This used to be commit ece9507ec3d363fccf56b000ad9758780a9b3fb4)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/tdb/tdb.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c index 5bb75ffe07..4143ac7781 100644 --- a/source3/tdb/tdb.c +++ b/source3/tdb/tdb.c @@ -1048,6 +1048,12 @@ static int tdb_update(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf) } /* find an entry in the database given a key */ +/* If an entry doesn't exist tdb_err will be set to + * TDB_ERR_NOEXIST. If a key has no data attached + * tdb_err will not be set. Both will return a + * zero pptr and zero dsize. + */ + TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key) { tdb_off rec_ptr; @@ -1058,8 +1064,11 @@ TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key) if (!(rec_ptr = tdb_find_lock(tdb,key,F_RDLCK,&rec))) return tdb_null; - ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec) + rec.key_len, - rec.data_len); + if (rec.data_len) + ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec) + rec.key_len, + rec.data_len); + else + ret.dptr = NULL; ret.dsize = rec.data_len; tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK); return ret; |