It is perfectly valid to call free(NULL), so stop checking for non-NULL
authorjsing <jsing@openbsd.org>
Mon, 19 May 2014 12:13:30 +0000 (12:13 +0000)
committerjsing <jsing@openbsd.org>
Mon, 19 May 2014 12:13:30 +0000 (12:13 +0000)
before calling free - of some course parts of the code already did this.

29 files changed:
lib/libssl/src/apps/apps.c
lib/libssl/src/apps/ca.c
lib/libssl/src/apps/cms.c
lib/libssl/src/apps/dgst.c
lib/libssl/src/apps/dsa.c
lib/libssl/src/apps/ec.c
lib/libssl/src/apps/ecparam.c
lib/libssl/src/apps/enc.c
lib/libssl/src/apps/engine.c
lib/libssl/src/apps/gendsa.c
lib/libssl/src/apps/genpkey.c
lib/libssl/src/apps/genrsa.c
lib/libssl/src/apps/openssl.c
lib/libssl/src/apps/passwd.c
lib/libssl/src/apps/pkcs12.c
lib/libssl/src/apps/pkcs8.c
lib/libssl/src/apps/pkey.c
lib/libssl/src/apps/pkeyutl.c
lib/libssl/src/apps/req.c
lib/libssl/src/apps/rsa.c
lib/libssl/src/apps/rsautl.c
lib/libssl/src/apps/s_client.c
lib/libssl/src/apps/s_server.c
lib/libssl/src/apps/s_socket.c
lib/libssl/src/apps/smime.c
lib/libssl/src/apps/speed.c
lib/libssl/src/apps/spkac.c
lib/libssl/src/apps/ts.c
lib/libssl/src/apps/x509.c

index 7c15241..75f9fae 100644 (file)
@@ -1932,18 +1932,16 @@ parse_name(char *subject, long chtype, int multirdn)
        free(ne_types);
        free(buf);
        free(mval);
+
        return n;
 
 error:
        X509_NAME_free(n);
-       if (ne_values)
-               free(ne_values);
-       if (ne_types)
-               free(ne_types);
-       if (mval)
-               free(mval);
-       if (buf)
-               free(buf);
+       free(ne_values);
+       free(ne_types);
+       free(mval);
+       free(buf);
+
        return NULL;
 }
 
@@ -2131,6 +2129,7 @@ pkey_ctrl_string(EVP_PKEY_CTX * ctx, char *value)
        }
        rv = EVP_PKEY_CTX_ctrl_str(ctx, stmp, vtmp);
        free(stmp);
+
        return rv;
 }
 
index 10b5c0b..8217f36 100644 (file)
@@ -530,10 +530,9 @@ bad:
                            errorline, configfile);
                goto err;
        }
-       if (tofree) {
-               free(tofree);
-               tofree = NULL;
-       }
+       free(tofree);
+       tofree = NULL;
+
        if (!load_config(bio_err, conf))
                goto err;
 
@@ -1347,8 +1346,8 @@ bad:
        ret = 0;
 
 err:
-       if (tofree)
-               free(tofree);
+       free(tofree);
+
        BIO_free_all(Cout);
        BIO_free_all(Sout);
        BIO_free_all(out);
@@ -1996,8 +1995,7 @@ again2:
        ok = 1;
 err:
        for (i = 0; i < DB_NUMBER; i++)
-               if (row[i] != NULL)
-                       free(row[i]);
+               free(row[i]);
 
        if (CAname != NULL)
                X509_NAME_free(CAname);
@@ -2287,10 +2285,9 @@ do_revoke(X509 * x509, CA_DB * db, int type, char *value)
        ok = 1;
 
 err:
-       for (i = 0; i < DB_NUMBER; i++) {
-               if (row[i] != NULL)
-                       free(row[i]);
-       }
+       for (i = 0; i < DB_NUMBER; i++)
+               free(row[i]);
+
        return (ok);
 }
 
@@ -2360,10 +2357,9 @@ get_certificate_status(const char *serial, CA_DB * db)
        }
 
 err:
-       for (i = 0; i < DB_NUMBER; i++) {
-               if (row[i] != NULL)
-                       free(row[i]);
-       }
+       for (i = 0; i < DB_NUMBER; i++)
+               free(row[i]);
+
        return (ok);
 }
 
@@ -2575,8 +2571,8 @@ make_revoked(X509_REVOKED * rev, const char *str)
                ret = 1;
 
 err:
-       if (tmp)
-               free(tmp);
+       free(tmp);
+
        ASN1_OBJECT_free(hold);
        ASN1_GENERALIZEDTIME_free(comp_time);
        ASN1_ENUMERATED_free(rtmp);
@@ -2719,8 +2715,8 @@ unpack_revinfo(ASN1_TIME ** prevtm, int *preason, ASN1_OBJECT ** phold,
        ret = 1;
 
 err:
-       if (tmp)
-               free(tmp);
+       free(tmp);
+
        if (!phold)
                ASN1_OBJECT_free(hold);
        if (!pinvtm)
index 01b4a2a..d85690c 100644 (file)
@@ -973,12 +973,9 @@ end:
                sk_OPENSSL_STRING_free(sksigners);
        if (skkeys)
                sk_OPENSSL_STRING_free(skkeys);
-       if (secret_key)
-               free(secret_key);
-       if (secret_keyid)
-               free(secret_keyid);
-       if (pwri_tmp)
-               free(pwri_tmp);
+       free(secret_key);
+       free(secret_keyid);
+       free(pwri_tmp);
        if (econtent_type)
                ASN1_OBJECT_free(econtent_type);
        if (rr)
@@ -998,8 +995,7 @@ end:
        BIO_free(in);
        BIO_free(indata);
        BIO_free_all(out);
-       if (passin)
-               free(passin);
+       free(passin);
        return (ret);
 }
 
index c183229..1017a36 100644 (file)
@@ -476,16 +476,14 @@ end:
        }
        if (in != NULL)
                BIO_free(in);
-       if (passin)
-               free(passin);
+       free(passin);
        BIO_free_all(out);
        EVP_PKEY_free(sigkey);
        if (sigopts)
                sk_OPENSSL_STRING_free(sigopts);
        if (macopts)
                sk_OPENSSL_STRING_free(macopts);
-       if (sigbuf)
-               free(sigbuf);
+       free(sigbuf);
        if (bmd != NULL)
                BIO_free(bmd);
        
index 4026ba5..c35d150 100644 (file)
@@ -332,10 +332,8 @@ end:
                BIO_free_all(out);
        if (dsa != NULL)
                DSA_free(dsa);
-       if (passin)
-               free(passin);
-       if (passout)
-               free(passout);
+       free(passin);
+       free(passout);
        
        return (ret);
 }
index 6bd71c3..452d73c 100644 (file)
@@ -339,10 +339,8 @@ end:
                BIO_free_all(out);
        if (eckey)
                EC_KEY_free(eckey);
-       if (passin)
-               free(passin);
-       if (passout)
-               free(passout);
+       free(passin);
+       free(passout);
        
        return (ret);
 }
index e6d3ae7..3e8b723 100644 (file)
@@ -587,8 +587,7 @@ end:
                BN_free(ec_order);
        if (ec_cofactor)
                BN_free(ec_cofactor);
-       if (buffer)
-               free(buffer);
+       free(buffer);
        if (in != NULL)
                BIO_free(in);
        if (out != NULL)
index b31d103..394995f 100644 (file)
@@ -609,10 +609,8 @@ enc_main(int argc, char **argv)
        }
 end:
        ERR_print_errors(bio_err);
-       if (strbuf != NULL)
-               free(strbuf);
-       if (buff != NULL)
-               free(buff);
+       free(strbuf);
+       free(buff);
        if (in != NULL)
                BIO_free(in);
        if (out != NULL)
@@ -625,8 +623,7 @@ end:
        if (bzl != NULL)
                BIO_free(bzl);
 #endif
-       if (pass)
-               free(pass);
+       free(pass);
        
        return (ret);
 }
index 2cf7bd2..07d6926 100644 (file)
@@ -259,10 +259,9 @@ util_verbose(ENGINE * e, int verbose, BIO * bio_out, const char *indent)
                }
                free(name);
                name = NULL;
-               if (desc) {
-                       free(desc);
-                       desc = NULL;
-               }
+               free(desc);
+               desc = NULL;
+
                /* Move to the next command */
                num = ENGINE_ctrl(e, ENGINE_CTRL_GET_NEXT_CMD_TYPE,
                    num, NULL, NULL);
@@ -273,10 +272,8 @@ util_verbose(ENGINE * e, int verbose, BIO * bio_out, const char *indent)
 err:
        if (cmds)
                sk_OPENSSL_STRING_pop_free(cmds, identity);
-       if (name)
-               free(name);
-       if (desc)
-               free(desc);
+       free(name);
+       free(desc);
        return ret;
 }
 
index cada26b..f4f3fb0 100644 (file)
@@ -238,8 +238,7 @@ end:
                BIO_free_all(out);
        if (dsa != NULL)
                DSA_free(dsa);
-       if (passout)
-               free(passout);
+       free(passout);
        
        return (ret);
 }
index 5797de4..fcd02ca 100644 (file)
@@ -262,8 +262,7 @@ end:
        if (out)
                BIO_free_all(out);
        BIO_free(in);
-       if (pass)
-               free(pass);
+       free(pass);
 
        return ret;
 }
index 96a678c..899a99f 100644 (file)
@@ -274,8 +274,7 @@ err:
                RSA_free(rsa);
        if (out)
                BIO_free_all(out);
-       if (passout)
-               free(passout);
+       free(passout);
        if (ret != 0)
                ERR_print_errors(bio_err);
        
index 4742803..272df02 100644 (file)
@@ -371,8 +371,7 @@ end:
        }
        if (prog != NULL)
                lh_FUNCTION_free(prog);
-       if (arg.data != NULL)
-               free(arg.data);
+       free(arg.data);
 
        openssl_shutdown();
 
index e87aed3..e9d0949 100644 (file)
@@ -245,10 +245,8 @@ passwd_main(int argc, char **argv)
 
 err:
        ERR_print_errors(bio_err);
-       if (salt_malloc)
-               free(salt_malloc);
-       if (passwd_malloc)
-               free(passwd_malloc);
+       free(salt_malloc);
+       free(passwd_malloc);
        if (in)
                BIO_free(in);
        if (out)
index aca248a..5b85f97 100644 (file)
@@ -697,10 +697,8 @@ end:
        BIO_free_all(out);
        if (canames)
                sk_OPENSSL_STRING_free(canames);
-       if (passin)
-               free(passin);
-       if (passout)
-               free(passout);
+       free(passin);
+       free(passout);
        
        return (ret);
 }
index 1f1a11e..4cedc40 100644 (file)
@@ -363,10 +363,8 @@ end:
        EVP_PKEY_free(pkey);
        BIO_free_all(out);
        BIO_free(in);
-       if (passin)
-               free(passin);
-       if (passout)
-               free(passout);
+       free(passin);
+       free(passout);
 
        return ret;
 }
index 101ba5b..4ec19b9 100644 (file)
@@ -231,10 +231,8 @@ end:
        EVP_PKEY_free(pkey);
        BIO_free_all(out);
        BIO_free(in);
-       if (passin)
-               free(passin);
-       if (passout)
-               free(passout);
+       free(passin);
+       free(passout);
 
        return ret;
 }
index 46392e6..4f1cfed 100644 (file)
@@ -322,12 +322,10 @@ end:
                EVP_PKEY_CTX_free(ctx);
        BIO_free(in);
        BIO_free_all(out);
-       if (buf_in)
-               free(buf_in);
-       if (buf_out)
-               free(buf_out);
-       if (sig)
-               free(sig);
+       free(buf_in);
+       free(buf_out);
+       free(sig);
+
        return ret;
 }
 
index 21ddb3b..d306a17 100644 (file)
@@ -912,8 +912,7 @@ end:
        if (gen_eng)
                ENGINE_free(gen_eng);
 #endif
-       if (keyalgstr)
-               free(keyalgstr);
+       free(keyalgstr);
        X509_REQ_free(req);
        X509_free(x509ss);
        ASN1_INTEGER_free(serial);
index 0b9c87d..f651f61 100644 (file)
@@ -391,10 +391,8 @@ end:
                BIO_free_all(out);
        if (rsa != NULL)
                RSA_free(rsa);
-       if (passin)
-               free(passin);
-       if (passout)
-               free(passout);
+       free(passin);
+       free(passout);
        
        return (ret);
 }
index 55c89b2..08d28a4 100644 (file)
@@ -305,16 +305,15 @@ rsautl_main(int argc, char **argv)
                BIO_dump(out, (char *) rsa_out, rsa_outlen);
        else
                BIO_write(out, rsa_out, rsa_outlen);
+
 end:
        RSA_free(rsa);
        BIO_free(in);
        BIO_free_all(out);
-       if (rsa_in)
-               free(rsa_in);
-       if (rsa_out)
-               free(rsa_out);
-       if (passin)
-               free(passin);
+       free(rsa_in);
+       free(rsa_out);
+       free(passin);
+
        return ret;
 }
 
index d29f147..bf4a7e0 100644 (file)
@@ -1411,8 +1411,7 @@ end:
                SSL_free(con);
        }
 #if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
-       if (next_proto.data)
-               free(next_proto.data);
+       free(next_proto.data);
 #endif
        if (ctx != NULL)
                SSL_CTX_free(ctx);
@@ -1420,8 +1419,7 @@ end:
                X509_free(cert);
        if (key)
                EVP_PKEY_free(key);
-       if (pass)
-               free(pass);
+       free(pass);
        if (vpm)
                X509_VERIFY_PARAM_free(vpm);
        if (cbuf != NULL) {
index 333e09f..99ebee4 100644 (file)
@@ -1457,10 +1457,8 @@ end:
                EVP_PKEY_free(s_key);
        if (s_dkey)
                EVP_PKEY_free(s_dkey);
-       if (pass)
-               free(pass);
-       if (dpass)
-               free(dpass);
+       free(pass);
+       free(dpass);
        if (vpm)
                X509_VERIFY_PARAM_free(vpm);
 #ifndef OPENSSL_NO_TLSEXT
index a9bbe97..3d88cdf 100644 (file)
@@ -167,8 +167,7 @@ do_server(int port, int type, int *ret,
                } else
                        sock = accept_socket;
                i = (*cb) (name, sock, context);
-               if (name != NULL)
-                       free(name);
+               free(name);
                if (type == SOCK_STREAM) {
                        shutdown(sock, SHUT_RDWR);
                        close(sock);
index 78d783d..69d47ee 100644 (file)
@@ -670,8 +670,8 @@ end:
        BIO_free(in);
        BIO_free(indata);
        BIO_free_all(out);
-       if (passin)
-               free(passin);
+       free(passin);
+
        return (ret);
 }
 
index 6bcb943..d25db09 100644 (file)
@@ -2013,10 +2013,8 @@ show_res:
 
 end:
        ERR_print_errors(bio_err);
-       if (buf != NULL)
-               free(buf);
-       if (buf2 != NULL)
-               free(buf2);
+       free(buf);
+       free(buf2);
 #ifndef OPENSSL_NO_RSA
        for (i = 0; i < RSA_NUM; i++)
                if (rsa_key[i] != NULL)
index 2fa7eac..33791c6 100644 (file)
@@ -280,8 +280,7 @@ end:
        BIO_free(in);
        BIO_free_all(out);
        EVP_PKEY_free(pkey);
-       if (passin)
-               free(passin);
+       free(passin);
        
        return (ret);
 }
index 2bb343d..2674de9 100644 (file)
@@ -548,6 +548,7 @@ err:
        free(data);
        ASN1_OBJECT_free(policy_obj);
        ASN1_INTEGER_free(nonce_asn1);
+
        return ts_req;
 }
 
index a488623..e77fd4d 100644 (file)
@@ -939,8 +939,7 @@ end:
        ASN1_INTEGER_free(sno);
        sk_ASN1_OBJECT_pop_free(trust, ASN1_OBJECT_free);
        sk_ASN1_OBJECT_pop_free(reject, ASN1_OBJECT_free);
-       if (passin)
-               free(passin);
+       free(passin);
        
        return (ret);
 }
@@ -983,9 +982,9 @@ x509_load_serial(char *CAfile, char *serialfile, int create)
                goto end;
 
 end:
-       if (buf)
-               free(buf);
+       free(buf);
        BN_free(serial);
+
        return bs;
 }