summaryrefslogtreecommitdiff
path: root/example.c
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2013-01-26 11:18:45 -0800
committerPieter Noordhuis <pcnoordhuis@gmail.com>2013-01-26 11:18:45 -0800
commitf05909cd53b1c0f983e2d645205d036784f0b39b (patch)
tree8738a33e728a53c7b521f2f87bec569245650fc3 /example.c
parent9df327e8fddef1e17b2136b5f42be58f46cdbc08 (diff)
parentd7e3268f48b457cb52336d264f8860b336faea9f (diff)
Merge pull request #147 from hdoreau/d7e3268f48b457cb52336d264f8860b336faea9f
Prevent hiredis from crashing on memory allocation failure
Diffstat (limited to 'example.c')
-rw-r--r--example.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/example.c b/example.c
index 378ef71..d9d7271 100644
--- a/example.c
+++ b/example.c
@@ -11,8 +11,13 @@ int main(void) {
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
c = redisConnectWithTimeout((char*)"127.0.0.1", 6379, timeout);
- if (c->err) {
- printf("Connection error: %s\n", c->errstr);
+ if (c == NULL || c->err) {
+ if (c) {
+ printf("Connection error: %s\n", c->errstr);
+ redisFree(c);
+ } else {
+ printf("Connection error: can't allocate redis context\n");
+ }
exit(1);
}