Commit 74d000ae authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Implement redis_object destroy callback

parent 5bd66cae
......@@ -159,7 +159,12 @@ static int _object_nil_cb(redis_parser *parser, redis_protocol *p) {
}
static void _object_destroy_cb(redis_parser *parser, redis_protocol *p) {
assert(NULL);
redis_object *self;
((void)parser);
self = p->data;
redis_object_free(&self);
}
/* Set of callbacks that can be passed to the parser. */
......
......@@ -215,6 +215,22 @@ void test_empty_error(redis_parser *parser) {
redis_object_free(&obj);
}
void test_destroy_callback(redis_parser *parser) {
const char *buf = "+ok\r";
redis_protocol *res;
redis_parser_init(parser, &redis_object_parser_callbacks);
assert(redis_parser_execute(parser, &res, buf, strlen(buf)) == strlen(buf));
assert(res == NULL);
assert(redis_parser_err(parser) == RPE_OK);
/* Go ahead and let the parser clean up */
redis_parser_destroy(parser);
/* No way to check if the temporary object gets properly free'd.
* Let's hope that Valgrind starts complaining when this is buggy. */
}
int main(int argc, char **argv) {
redis_parser *parser = malloc(sizeof(redis_parser));
......@@ -237,6 +253,8 @@ int main(int argc, char **argv) {
test_error(parser);
test_empty_error(parser);
test_destroy_callback(parser);
free(parser);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment