From 6ada988a2f0877094e6749ca43878a86bf9a4ffb Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 16 Apr 2020 21:21:47 -0400 Subject: nserver: Update sslist. * nserver/src/protocol.c (sslist): Don't bomb whent tst is null; just return "EMPTY". Also bcstrfree the c string return by bstr2cstr. --- nserver/src/protocol.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c index 4c7b94f..d5a520b 100644 --- a/nserver/src/protocol.c +++ b/nserver/src/protocol.c @@ -192,7 +192,16 @@ void traverse_tree(void *value, void *data) char *sslist() { - check(tst != NULL, "tstree not initialized"); + char *list = NULL, *tmp = NULL; + + if (tst == NULL) { + list = (char *) calloc(7 + 1, sizeof(char)); + check_mem(list); + + list = strncpy(list, "EMPTY\n\r", 7); + + return list; + } // 1. Create "accumulator" string. bstring ks_str = bfromcstr(""); @@ -201,9 +210,23 @@ char *sslist() // 2. Accumulate keys into "accumulator" string. TSTree_traverse(tst, traverse_tree, ks_str); + // 3. Make result. + tmp = bstr2cstr(ks_str, ' '); + + list = (char *) calloc(strlen(tmp) + 1, sizeof(char)); + check_mem(list); + + list = strncpy(list, tmp, strlen(tmp)); + + // 4. Clean up. + bcstrfree(tmp); + // 3. Return result. - return bstr2cstr(ks_str, ' '); + return list; error: + if (tmp) { + bcstrfree(tmp); + } return NULL; } -- cgit v1.2.3