antirez/hiredis — Issue #87: redisConnect may return null pointer
Author: illdefined
Created: 2012-02-19 18:42:37+00:00
State: open

The documentation recommends to check the `err` field of the `redisContext` structure to verify whether a call to `redisConnect()` was successful:

redisContext *c = redisConnect("127.0.0.1", 6379);
if (c->err) {
printf("Error: %s\n", c->errstr);
// handle error
}

Unfortunately, if no memory can be allocated for the `redisContext` structure, `redisConnect()` will return a null pointer, making it a bad idea to try to access the `err` field.

Although I managed to trigger this error only once, I suggest to update the documentation to consider the possibility:

redisContext *c = redisConnect("127.0.0.1", 6379);
if (!c || c->err) {
printf("Error: %s\n", c ? c->errstr : "redisContext allocation failed");
// handle error
}