diff options
author | Volker Lendecke <vl@samba.org> | 2013-04-05 13:11:31 +1100 |
---|---|---|
committer | Amitay Isaacs <amitay@gmail.com> | 2013-04-05 13:12:58 +1100 |
commit | a37033bfc9147189c034dbc63758c4aa4af03685 (patch) | |
tree | 6df445bf5f10e51d93514d8cff39c1a30e107f0c /ctdb/common/ctdb_message.c | |
parent | 9937adf0ca6d967803e3cf2327e53abe8e3a75f4 (diff) | |
download | samba-a37033bfc9147189c034dbc63758c4aa4af03685.tar.gz |
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)
Diffstat (limited to 'ctdb/common/ctdb_message.c')
-rw-r--r-- | ctdb/common/ctdb_message.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/ctdb/common/ctdb_message.c b/ctdb/common/ctdb_message.c index a556ac4336a..9700caf42e5 100644 --- a/ctdb/common/ctdb_message.c +++ b/ctdb/common/ctdb_message.c @@ -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); } /* |