Repository: Shardcached/libshardcache (language: python)

Issue:
Remove unnecessary null pointer checks
[An extra null pointer check is not needed](http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html) in functions like the following.
- [destroy_volatile](https://github.com/Shardcached/libshardcache/blob/2b80330ff8b31630178cd4bff8e5112190510bae/src/shardcache.c#L294)
- [kepaxos_command_free](https://github.com/Shardcached/libshardcache/blob/dc0fffe246c246ac1b27f644731a4cb561f0c0b4/src/kepaxos.c#L106)

Would you like to apply the following [semantic patch](http://coccinelle.lip6.fr/) to find more update candidates?

```
@Remove_unnecessary_pointer_checks@
expression x;
@@
-if (x)
    free(x);
```



Discussion / hints:
9901bad1b65ea198c992ab15fed3a3815ee47188

Thanks for [your small source code improvement](https://github.com/Shardcached/libshardcache/commit/9901bad1b65ea198c992ab15fed3a3815ee47188).


Fix patch:
diff --git a/src/shardcache_client.c b/src/shardcache_client.c
index 47ae1d2..6de75a1 100644
--- a/src/shardcache_client.c
+++ b/src/shardcache_client.c
@@ -1219,12 +1219,10 @@ async_job_destroy(async_job_t *job)
             free(job->arg.single.key);
             if (job->arg.single.fd >= 0)
                 close(job->arg.single.fd);
-            if (job->arg.single.wrk)
-                free(job->arg.single.wrk);
+            free(job->arg.single.wrk);
             break;
         case JOB_CMD_GET_MULTI:
-            if (job->arg.multi.pools)
-                list_destroy(job->arg.multi.pools);
+            list_destroy(job->arg.multi.pools);
             if (job->arg.multi.contexts) {
                 shc_multi_ctx_t *ctx = NULL;
                 while ((ctx = list_shift_value(job->arg.multi.contexts)))
diff --git a/utils/shardcachec.c b/utils/shardcachec.c
index 6af0e23..efc5b95 100644
--- a/utils/shardcachec.c
+++ b/utils/shardcachec.c
@@ -221,8 +221,7 @@ int main (int argc, char **argv) {
             shc_multi_item_destroy(items[i]);
             if (out)
                 fclose(out);
-            if (outname)
-                free(outname);
+            free(outname);
         }
     } else if (strcasecmp(cmd, "set") == 0 ||
                strcasecmp(cmd, "add") == 0)
@@ -313,8 +312,7 @@ int main (int argc, char **argv) {
                 printf("%s\n", stats);
             else
                 printf("Error querying node: %s (%s)\n", label, address);
-            if (stats)
-                free(stats);
+            free(stats);
             printf("\n");
         }
         if (found == 0 && selected_node)
diff --git a/utils/shc_benchmark.c b/utils/shc_benchmark.c
index 3185bd5..fcd0307 100644
--- a/utils/shc_benchmark.c
+++ b/utils/shc_benchmark.c
@@ -547,8 +547,7 @@ main (int argc, char **argv)
                                : counts[i].value;
                 if (!slowest_client || (diff > 0 && slowest_client > diff)) {
                     slowest_client = diff;
-                    if (slowest_label)
-                        free(slowest_label);
+                    free(slowest_label);
                     slowest_label = strdup(counts[i].name);
                 }
 
@@ -595,8 +594,7 @@ main (int argc, char **argv)
                    fastest_client,
                    stuck_clients);
         }
-        if (slowest_label)
-            free(slowest_label);
+        free(slowest_label);
 
         if (stats_file) {
             char line[(10*9) + 10];
@@ -621,8 +619,7 @@ main (int argc, char **argv)
 
 
         num_responses_prev = __sync_add_and_fetch(&num_responses, 0);
-        if (counts)
-            free(counts);
+        free(counts);
     }
 
     for (i = 0; i < num_threads; i++) {


Test patch:
diff --git a/test/shardcache_test.c b/test/shardcache_test.c
index aa3a96d..16921c9 100644
--- a/test/shardcache_test.c
+++ b/test/shardcache_test.c
@@ -154,8 +154,7 @@ int main(int argc, char **argv)
             ut_failure("%s != %s", vv, v);
             failed = 1;
         }
-        if (vv)
-            free(vv);
+        free(vv);
         int count = i - 100;
         if (count%10 == 0)
             ut_progress(count);