mirror of
https://github.com/samba-team/samba.git
synced 2025-08-26 01:49:31 +03:00
common/messaging: use tdb_parse_record in message_list_db_fetch
This avoids malloc/free in a hot code path. (This used to be ctdb commit c137531fae8f7f6392746ce1b9ac6f219775fc29)
This commit is contained in:
committed by
Amitay Isaacs
parent
9937adf0ca
commit
a37033bfc9
@ -92,10 +92,24 @@ static int message_list_db_delete(struct ctdb_context *ctdb, uint64_t srvid)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int message_list_db_fetch_parser(TDB_DATA key, TDB_DATA data,
|
||||
void *private_data)
|
||||
{
|
||||
struct ctdb_message_list_header **h =
|
||||
(struct ctdb_message_list_header **)private_data;
|
||||
|
||||
if (data.dsize != sizeof(struct ctdb_message_list_header *)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*h = *(struct ctdb_message_list_header **)data.dptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int message_list_db_fetch(struct ctdb_context *ctdb, uint64_t srvid,
|
||||
struct ctdb_message_list_header **h)
|
||||
{
|
||||
TDB_DATA key, data;
|
||||
TDB_DATA key;
|
||||
|
||||
if (ctdb->message_list_indexdb == NULL) {
|
||||
return -1;
|
||||
@ -104,16 +118,8 @@ static int message_list_db_fetch(struct ctdb_context *ctdb, uint64_t srvid,
|
||||
key.dptr = (uint8_t *)&srvid;
|
||||
key.dsize = sizeof(uint64_t);
|
||||
|
||||
data = tdb_fetch(ctdb->message_list_indexdb, key);
|
||||
if (data.dsize != sizeof(struct ctdb_message_list_header *)) {
|
||||
talloc_free(data.dptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*h = *(struct ctdb_message_list_header **)data.dptr;
|
||||
talloc_free(data.dptr);
|
||||
|
||||
return 0;
|
||||
return tdb_parse_record(ctdb->message_list_indexdb, key,
|
||||
message_list_db_fetch_parser, h);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user