Skip to content

Commit

Permalink
cachedb_redis: Fix build; Fix couple PKG memleaks
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Jan 10, 2025
1 parent 1977206 commit 821851f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cachedb/cachedb_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 7 additions & 8 deletions modules/cachedb_redis/cachedb_redis_dbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 821851f

Please sign in to comment.