From 10c067668a5c35d5eac940dd51f77e7687fc5bb7 Mon Sep 17 00:00:00 2001 From: kanoi Date: Sat, 12 Mar 2016 16:44:34 +1100 Subject: [PATCH] ckdb - event_tree() can realloc buf, so must pass buf address --- src/ckdb.h | 2 +- src/ckdb_cmd.c | 37 ++++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index 50cdf576..f3fdec29 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -51,7 +51,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.5" -#define CKDB_VERSION DB_VERSION"-1.980" +#define CKDB_VERSION DB_VERSION"-1.981" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index b43b32c3..e595e032 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -7551,48 +7551,51 @@ static char *cmd_locks(__maybe_unused PGconn *conn, char *cmd, char *id, return strdup(reply); } -static void event_tree(K_TREE *event_tree, char *list, char *reply, size_t siz, - char *buf, size_t *off, size_t *len, int *rows) +static void event_tree(K_TREE *the_tree, char *list, char *reply, size_t siz, + char **buf, size_t *off, size_t *len, int *rows) { K_TREE_CTX ctx[1]; K_ITEM *e_item; EVENTS *e; - e_item = first_in_ktree(event_tree, ctx); + LOGDEBUG(">%s() tree='%s' list='%s'", __func__, the_tree->name, list); + e_item = first_in_ktree(the_tree, ctx); while (e_item) { DATA_EVENTS(e, e_item); if (CURRENT(&(e->expirydate))) { snprintf(reply, siz, "list:%d=%s%c", *rows, list, FLDSEP); - APPEND_REALLOC(buf, *off, *len, reply); + APPEND_REALLOC(*buf, *off, *len, reply); snprintf(reply, siz, "id:%d=%d%c", *rows, e->id, FLDSEP); - APPEND_REALLOC(buf, *off, *len, reply); + APPEND_REALLOC(*buf, *off, *len, reply); snprintf(reply, siz, "user:%d=%s%c", *rows, e->createby, FLDSEP); - APPEND_REALLOC(buf, *off, *len, reply); + APPEND_REALLOC(*buf, *off, *len, reply); - if (event_tree == events_ipc_root) { + if (the_tree == events_ipc_root) { snprintf(reply, siz, "ipc:%d=%s%c", *rows, e->ipc, FLDSEP); - APPEND_REALLOC(buf, *off, *len, reply); + APPEND_REALLOC(*buf, *off, *len, reply); } else { snprintf(reply, siz, "ip:%d=%s%c", *rows, e->createinet, FLDSEP); - APPEND_REALLOC(buf, *off, *len, reply); + APPEND_REALLOC(*buf, *off, *len, reply); } - if (event_tree == events_hash_root) { + if (the_tree == events_hash_root) { snprintf(reply, siz, "hash:%d=%.8s%c", *rows, e->hash, FLDSEP); - APPEND_REALLOC(buf, *off, *len, reply); + APPEND_REALLOC(*buf, *off, *len, reply); } snprintf(reply, siz, CDTRF":%d=%ld%c", - (*rows)++, e->createdate.tv_sec, FLDSEP); - APPEND_REALLOC(buf, *off, *len, reply); + *rows, e->createdate.tv_sec, FLDSEP); + APPEND_REALLOC(*buf, *off, *len, reply); + + (*rows)++; } e_item = next_in_ktree(ctx); } @@ -7718,22 +7721,22 @@ static char *cmd_events(__maybe_unused PGconn *conn, char *cmd, char *id, K_RLOCK(events_free); if (all || strcmp(list, "user") == 0) { one = true; - event_tree(events_user_root, "user", reply, siz, buf, + event_tree(events_user_root, "user", reply, siz, &buf, &off, &len, &rows); } if (all || strcmp(list, "ip") == 0) { one = true; - event_tree(events_ip_root, "ip", reply, siz, buf, + event_tree(events_ip_root, "ip", reply, siz, &buf, &off, &len, &rows); } if (all || strcmp(list, "ipc") == 0) { one = true; - event_tree(events_ipc_root, "ipc", reply, siz, buf, + event_tree(events_ipc_root, "ipc", reply, siz, &buf, &off, &len, &rows); } if (all || strcmp(list, "hash") == 0) { one = true; - event_tree(events_hash_root, "hash", reply, siz, buf, + event_tree(events_hash_root, "hash", reply, siz, &buf, &off, &len, &rows); } K_RUNLOCK(events_free);