Remove unnecessary NULL checks, part 1.

First batch of the alphabet.

Change-Id: If4e60f4fbb69e04eb4b70aa1b2240e329251bfa5
Reviewed-on: https://boringssl-review.googlesource.com/4514
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/bn/bn.c b/crypto/bn/bn.c
index f89b6f1..f32d6b0 100644
--- a/crypto/bn/bn.c
+++ b/crypto/bn/bn.c
@@ -88,7 +88,7 @@
     return;
   }
 
-  if (bn->d != NULL && (bn->flags & BN_FLG_STATIC_DATA) == 0) {
+  if ((bn->flags & BN_FLG_STATIC_DATA) == 0) {
     OPENSSL_free(bn->d);
   }
 
@@ -304,9 +304,7 @@
 
   memcpy(a, bn->d, sizeof(BN_ULONG) * bn->top);
 
-  if (bn->d) {
-    OPENSSL_free(bn->d);
-  }
+  OPENSSL_free(bn->d);
   bn->d = a;
   bn->dmax = words;
 
diff --git a/crypto/bn/convert.c b/crypto/bn/convert.c
index 9c7b9be..531b661 100644
--- a/crypto/bn/convert.c
+++ b/crypto/bn/convert.c
@@ -407,13 +407,9 @@
   ok = 1;
 
 err:
-  if (bn_data != NULL) {
-    OPENSSL_free(bn_data);
-  }
-  if (t != NULL) {
-    BN_free(t);
-  }
-  if (!ok && buf) {
+  OPENSSL_free(bn_data);
+  BN_free(t);
+  if (!ok) {
     OPENSSL_free(buf);
     buf = NULL;
   }
diff --git a/crypto/bn/ctx.c b/crypto/bn/ctx.c
index e3a5c92..0578376 100644
--- a/crypto/bn/ctx.c
+++ b/crypto/bn/ctx.c
@@ -205,9 +205,7 @@
 }
 
 static void BN_STACK_finish(BN_STACK *st) {
-  if (st->size) {
-    OPENSSL_free(st->indexes);
-  }
+  OPENSSL_free(st->indexes);
 }
 
 static int BN_STACK_push(BN_STACK *st, unsigned int idx) {
@@ -222,9 +220,7 @@
     if (st->depth) {
       memcpy(newitems, st->indexes, st->depth * sizeof(unsigned int));
     }
-    if (st->size) {
-      OPENSSL_free(st->indexes);
-    }
+    OPENSSL_free(st->indexes);
     st->indexes = newitems;
     st->size = newsize;
   }
diff --git a/crypto/bn/div.c b/crypto/bn/div.c
index 8b0152e..3588ea1 100644
--- a/crypto/bn/div.c
+++ b/crypto/bn/div.c
@@ -492,9 +492,7 @@
 
   ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m));
 
-  if (abs_m) {
-    BN_free(abs_m);
-  }
+  BN_free(abs_m);
   return ret;
 }
 
diff --git a/crypto/bn/exponentiation.c b/crypto/bn/exponentiation.c
index 57f319a..d3063c9 100644
--- a/crypto/bn/exponentiation.c
+++ b/crypto/bn/exponentiation.c
@@ -763,7 +763,7 @@
   ret = 1;
 
 err:
-  if (in_mont == NULL && mont != NULL) {
+  if (in_mont == NULL) {
     BN_MONT_CTX_free(mont);
   }
   BN_CTX_end(ctx);
@@ -878,8 +878,7 @@
   BN_CTX_start(ctx);
 
   /* Allocate a montgomery context if it was not supplied by the caller.
-   * If this is not done, things will break in the montgomery part.
-   */
+   * If this is not done, things will break in the montgomery part. */
   if (in_mont != NULL) {
     mont = in_mont;
   } else {
@@ -1191,14 +1190,12 @@
   }
   ret = 1;
 err:
-  if ((in_mont == NULL) && (mont != NULL)) {
+  if (in_mont == NULL) {
     BN_MONT_CTX_free(mont);
   }
   if (powerbuf != NULL) {
     OPENSSL_cleanse(powerbuf, powerbufLen);
-    if (powerbufFree) {
-      OPENSSL_free(powerbufFree);
-    }
+    OPENSSL_free(powerbufFree);
   }
   BN_CTX_end(ctx);
   return (ret);
@@ -1353,7 +1350,7 @@
   ret = 1;
 
 err:
-  if (in_mont == NULL && mont != NULL) {
+  if (in_mont == NULL) {
     BN_MONT_CTX_free(mont);
   }
   BN_CTX_end(ctx);
@@ -1557,7 +1554,7 @@
   ret = 1;
 
 err:
-  if (in_mont == NULL && mont != NULL) {
+  if (in_mont == NULL) {
     BN_MONT_CTX_free(mont);
   }
   BN_CTX_end(ctx);
diff --git a/crypto/bn/random.c b/crypto/bn/random.c
index 285bf26..3be7510 100644
--- a/crypto/bn/random.c
+++ b/crypto/bn/random.c
@@ -321,8 +321,6 @@
   ret = 1;
 
 err:
-  if (k_bytes) {
-    OPENSSL_free(k_bytes);
-  }
+  OPENSSL_free(k_bytes);
   return ret;
 }
diff --git a/crypto/bn/sqrt.c b/crypto/bn/sqrt.c
index 07041f9..e71a818 100644
--- a/crypto/bn/sqrt.c
+++ b/crypto/bn/sqrt.c
@@ -420,7 +420,7 @@
 
 end:
   if (err) {
-    if (ret != NULL && ret != in) {
+    if (ret != in) {
       BN_clear_free(ret);
     }
     ret = NULL;