@@ -880,24 +880,24 @@ static int do_test(const struct hash_testvec *tv)
880880 */
881881static int do_synthetic_once (const struct hash_testvec * tv , unsigned int shifts )
882882{
883- unsigned char * ibuf , * md ;
884- T (ibuf = OPENSSL_zalloc (SUPER_SIZE + shifts ));
883+ unsigned char * ibuf = NULL , * md_buf = NULL , * md = NULL ;
884+ unsigned int len , mdlen ;
885+ EVP_MD_CTX * ctx = NULL , * ctx2 = NULL ;
886+ EVP_MD * dgst = NULL ;
887+ int ret = 1 ;
885888
889+ T (ibuf = OPENSSL_zalloc (SUPER_SIZE + shifts ));
886890 /* fill with pattern */
887- unsigned int len ;
888891 for (len = 0 ; len < SUPER_SIZE ; len ++ )
889892 ibuf [shifts + len ] = len & 0xff ;
890893
891- EVP_MD * dgst ;
892894 T ((dgst = EVP_MD_fetch (NULL , tv -> algname , NULL ))
893895 || (dgst = (EVP_MD * )EVP_get_digestbyname (tv -> algname )));
894896 if (dgst && warn_md_impl_is_expected (dgst )) {
895- EVP_MD_free (dgst );
896- return 1 ;
897+ goto err ;
897898 }
898899
899900 OPENSSL_assert (EVP_MD_is_a (dgst , tv -> algname ));
900- EVP_MD_CTX * ctx , * ctx2 ;
901901 T (ctx = EVP_MD_CTX_new ());
902902 T (ctx2 = EVP_MD_CTX_new ());
903903 T (EVP_DigestInit (ctx2 , dgst ));
@@ -906,10 +906,10 @@ static int do_synthetic_once(const struct hash_testvec *tv, unsigned int shifts)
906906 OPENSSL_assert (EVP_MD_CTX_size (ctx2 ) == tv -> outsize );
907907 OPENSSL_assert (EVP_MD_CTX_block_size (ctx2 ) == tv -> block_size );
908908
909- const unsigned int mdlen = EVP_MD_size (dgst );
909+ mdlen = EVP_MD_size (dgst );
910910 OPENSSL_assert (mdlen == tv -> outsize );
911- T (md = OPENSSL_zalloc (mdlen + shifts ));
912- md += shifts ; /* test for output digest alignment problems */
911+ T (md_buf = OPENSSL_zalloc (mdlen + shifts ));
912+ md = md_buf + shifts ; /* test for output digest alignment problems */
913913
914914 /* digest cycles */
915915 for (len = 0 ; len < SUPER_SIZE ; len ++ ) {
@@ -928,13 +928,7 @@ static int do_synthetic_once(const struct hash_testvec *tv, unsigned int shifts)
928928 T (EVP_DigestUpdate (ctx2 , md , mdlen ));
929929 }
930930
931- OPENSSL_free (ibuf );
932- EVP_MD_CTX_free (ctx );
933-
934931 T (EVP_DigestFinal (ctx2 , md , & len ));
935- EVP_MD_CTX_free (ctx2 );
936-
937- EVP_MD_free (dgst );
938932
939933 if (len != mdlen ) {
940934 printf (cRED "digest output len mismatch %u != %u (expected)" cNORM "\n" ,
@@ -953,12 +947,14 @@ static int do_synthetic_once(const struct hash_testvec *tv, unsigned int shifts)
953947 goto err ;
954948 }
955949
956- OPENSSL_free (md - shifts );
957- return 0 ;
950+ ret = 0 ;
958951err :
959- OPENSSL_free (md - shifts );
952+ EVP_MD_CTX_free (ctx );
953+ EVP_MD_CTX_free (ctx2 );
954+ OPENSSL_free (md_buf );
955+ OPENSSL_free (ibuf );
960956 EVP_MD_free (dgst );
961- return 1 ;
957+ return ret ;
962958}
963959
964960/* do different block sizes and different memory offsets */
0 commit comments