From 821851f5097c45991f37f3932dc3790250e2bf6d Mon Sep 17 00:00:00 2001 From: Liviu Chircu Date: Fri, 10 Jan 2025 16:03:31 +0200 Subject: [PATCH] cachedb_redis: Fix build; Fix couple PKG memleaks --- cachedb/cachedb_dict.c | 2 +- modules/cachedb_redis/cachedb_redis_dbase.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cachedb/cachedb_dict.c b/cachedb/cachedb_dict.c index 6227c8481e..d0f50a4e59 100644 --- a/cachedb/cachedb_dict.c +++ b/cachedb/cachedb_dict.c @@ -478,7 +478,7 @@ char *cdb_dict_to_json(const cdb_dict_t *dict, break; case CDB_INT64: - i += sprintf(obj+i, "%ld", pair->val.val.i64); + i += sprintf(obj+i, "%lld", (long long)pair->val.val.i64); break; case CDB_NULL: diff --git a/modules/cachedb_redis/cachedb_redis_dbase.c b/modules/cachedb_redis/cachedb_redis_dbase.c index f850948f3d..ec4514e379 100644 --- a/modules/cachedb_redis/cachedb_redis_dbase.c +++ b/modules/cachedb_redis/cachedb_redis_dbase.c @@ -977,7 +977,6 @@ char *redis_mk_fts_filter(const cdb_filter_t *f) int redis_query(cachedb_con *_con, const cdb_filter_t *filter, cdb_res_t *res) { - //static char *keyspace = "usrloc"; /* FIXME */ redis_con *con = (redis_con *)_con->data; const char *argv[REDIS_ARGV_MAX_LEN]; size_t argvlen[REDIS_ARGV_MAX_LEN]; @@ -1274,7 +1273,7 @@ int redis_update_subkeys(cachedb_con *_con, const cdb_filter_t *row_filter, size_t argvlen[REDIS_ARGV_MAX_LEN]; cdb_pair_t *pair; redisReply *rpl = NULL; - str skey, key_nt; + str skey; int i, j, rc, subkeys_updated, subkeys_deleted; memset(argv, 0, REDIS_ARGV_MAX_LEN * sizeof *argv); @@ -1295,12 +1294,7 @@ int redis_update_subkeys(cachedb_con *_con, const cdb_filter_t *row_filter, argv[2] = "."; argvlen[2] = 1; - if (pkg_nt_str_dup(&key_nt, &row_filter->key.name) != 0) { - LM_ERR("oom\n"); - goto error1; - } - - if (cdb_dict_add_str((cdb_dict_t *)pairs, key_nt.s, key_nt.len, &row_filter->val.s) != 0) { + if (cdb_dict_add_str((cdb_dict_t *)pairs, row_filter->key.name.s, row_filter->key.name.len, &row_filter->val.s) != 0) { LM_ERR("oom 2\n"); goto error1; } @@ -1403,6 +1397,11 @@ int redis_update_subkeys(cachedb_con *_con, const cdb_filter_t *row_filter, LM_DBG("storing %d contacts at JSON key '%s' ...\n", (i-1)/3, argv[1]); rc = redis_run_command_argv(_con, &rpl, &skey, i, (const char **)argv, argvlen); + for (i -= 3; i > 0; i -= 3) { + pkg_free(argv[i+1]); argv[i+1] = NULL; + pkg_free(argv[i+2]); argv[i+2] = NULL; + } + if (rc < 0) { LM_ERR("failed to run JSON.MSET query (rc: %d), key: %s\n", rc, argv[1]); goto error2;