redis/hiredis — pull request #286 by badboy (2014-12-08 23:49:55+00:00)
Title: Free string if it is unused

If the string is already in the dict, we need to free this.

Original fix by @tt33415366.

Closes #256

Before:

```
% valgrind --leak-check=full ./mytest
==8591== Memcheck, a memory error detector
==8591== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==8591== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==8591== Command: ./mytest
==8591==
==8591==
==8591== HEAP SUMMARY:
==8591== in use at exit: 1,548 bytes in 9 blocks
==8591== total heap usage: 65 allocs, 56 frees, 4,233 bytes allocated
==8591==
==8591== 12 bytes in 1 blocks are definitely lost in loss record 1 of 9
==8591== at 0x4C29F90: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8591== by 0x406FF7: sdsnewlen (sds.c:55)
==8591== by 0x402199: __redisAsyncCommand (async.c:599)
==8591== by 0x403166: redisvAsyncCommand (async.c:639)
==8591== by 0x4031FC: redisAsyncCommand (async.c:648)
==8591== by 0x4014FA: main (mytest.c:80)
==8591==
==8591== LEAK SUMMARY:
==8591== definitely lost: 12 bytes in 1 blocks
==8591== indirectly lost: 0 bytes in 0 blocks
==8591== possibly lost: 0 bytes in 0 blocks
==8591== still reachable: 1,536 bytes in 8 blocks
==8591== suppressed: 0 bytes in 0 blocks
==8591== Reachable blocks (those to which a pointer was found) are not shown.
==8591== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==8591==
==8591== For counts of detected and suppressed errors, rerun with: -v
==8591== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
```

After:

```
% valgrind --leak-check=full ./mytest
==9001== Memcheck, a memory error detector
==9001== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==9001== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==9001== Command: ./mytest
==9001==
==9001==
==9001== HEAP SUMMARY:
==9001== in use at exit: 1,536 bytes in 8 blocks
==9001== total heap usage: 65 allocs, 57 frees, 4,233 bytes allocated
==9001==
==9001== LEAK SUMMARY:
==9001== definitely lost: 0 bytes in 0 blocks
==9001== indirectly lost: 0 bytes in 0 blocks
==9001== possibly lost: 0 bytes in 0 blocks
==9001== still reachable: 1,536 bytes in 8 blocks
==9001== suppressed: 0 bytes in 0 blocks
==9001== Reachable blocks (those to which a pointer was found) are not shown.
==9001== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==9001==
==9001== For counts of detected and suppressed errors, rerun with: -v
==9001== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0
```