made RMUtilInfo strdip all its keys and values for saner memory management

master
Dvir Volk 7 years ago
parent 5ccee1e4d0
commit 74a6c8c7fb

@ -57,9 +57,11 @@ RMUtilInfo *RMUtil_GetRedisInfo(RedisModuleCtx *ctx) {
info->entries = calloc(cap, sizeof(RMUtilInfoEntry));
int i = 0;
char *text = (char *)RedisModule_StringPtrLen(RedisModule_CreateStringFromCallReply(r), NULL);
size_t sz;
char *text = (char *)RedisModule_CallReplyStringPtr(r, &sz);
char *line = text;
while (line) {
while (line && line < text + sz) {
char *line = strsep(&text, "\r\n");
if (line == NULL) break;
@ -68,8 +70,8 @@ RMUtilInfo *RMUtil_GetRedisInfo(RedisModuleCtx *ctx) {
}
char *key = strsep(&line, ":");
info->entries[i].key = key;
info->entries[i].val = line;
info->entries[i].key = strdup(key);
info->entries[i].val = strdup(line);
i++;
if (i >= cap) {
cap *= 2;
@ -77,11 +79,14 @@ RMUtilInfo *RMUtil_GetRedisInfo(RedisModuleCtx *ctx) {
}
}
info->numEntries = i;
RedisModule_FreeCallReply(r);
return info;
}
void RMUtilRedisInfo_Free(RMUtilInfo *info) {
for (int i = 0; i < info->numEntries; i++) {
free(info->entries[i].key);
free(info->entries[i].val);
}
free(info->entries);
free(info);
}

@ -79,8 +79,8 @@ void RMUtil_DefaultAofRewrite(RedisModuleIO *aof, RedisModuleString *key, void *
// A single key/value entry in a redis info map
typedef struct {
const char *key;
const char *val;
char *key;
char *val;
} RMUtilInfoEntry;
// Representation of INFO command response, as a list of k/v pairs

Loading…
Cancel
Save