title: hiredis client, redisAsyncFree error when the connection is broken
body: <p>I'm writing a redis client software using hiredis, with async I/O. But it will crash when the connection broken, and redisAsyncFree is called.</p>
  
  <p>The main loop is like this:</p>
  
  <pre><code>RedisTask* theTask;
  OSQueueElem* theElem;
  redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
  printf("New redis context %p\n", c);
  redisLibevAttach(EV_DEFAULT_ c);
  redisAsyncSetConnectCallback(c,connectCallback);
  redisAsyncSetDisconnectCallback(c,disconnectCallback);
  
  while (true)
  {
      if (c &amp;&amp; c-&gt;err == 0)
      {
          theElem = NULL;
          theTask = NULL;
          theElem = fTaskQueue.DeQueue();
          if (theElem != NULL)
              theTask = (RedisTask*)theElem-&gt;GetEnclosingObject();
          if (theTask)
          {
              redisAsyncCommand(c, GenericCallback, (void*)theTask, theTask-&gt;GetCmd());
          }
          else
              OSThread::Sleep(kMinWaitTimeInMilSecs); // Is this necessary?
          ev_loop(EV_DEFAULT_ EVLOOP_NONBLOCK);
      }
      else
      {
          printf("redis connection broken, reconnect...\n");
          if (c)
          {
              printf("Free redis context %p\n", c);
              redisAsyncFree(c);
          }
          c = redisAsyncConnect("127.0.0.1", 6379);
          redisLibevAttach(EV_DEFAULT_ c);
          redisAsyncSetConnectCallback(c,connectCallback);
          redisAsyncSetDisconnectCallback(c,disconnectCallback);
      }
  }
  </code></pre>
  
  <p>Error occurs when redisAsyncFree is called. The backtrace is like this:</p>
  
  <pre><code>#0  0x00110402 in __kernel_vsyscall ()
  #1  0x0026bc00 in raise () from /lib/libc.so.6
  #2  0x0026d451 in abort () from /lib/libc.so.6
  #3  0x002a121b in __libc_message () from /lib/libc.so.6
  #4  0x002ac6fb in free () from /lib/libc.so.6
  #5  0x081287fd in _dictClear () at OSRef.h:75
  #6  0x0812881d in dictRelease () at OSRef.h:75
  #7  0x08129475 in __redisAsyncFree () at OSRef.h:75
  #8  0x08129839 in redisAsyncFree () at OSRef.h:75
  #9  0x0812d711 in RedisThread::Entry (this=0x8385aa0)
  </code></pre>
  
  <p>I'm wondering if my error handling logic is incorrect. So, the problem is, what is the correct logic for the case that c->err is non-zero in the loop? How to do the cleaning and reconnect to the server?</p>