Fix memory leak in sample encryption code and check return value of
fopen.
CLA: trivial
Signed-off-by: Greg Zaverucha <gregz@microsoft.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3790)
if (!EVP_EncryptUpdate(ctx, outbuf, &outlen, intext, strlen(intext))) {
/* Error */
+ EVP_CIPHER_CTX_free(ctx);
return 0;
}
/*
*/
if (!EVP_EncryptFinal_ex(ctx, outbuf + outlen, &tmplen)) {
/* Error */
+ EVP_CIPHER_CTX_free(ctx);
return 0;
}
outlen += tmplen;
* NULs.
*/
out = fopen(outfile, "wb");
+ if (out == NULL) {
+ /* Error */
+ return 0;
+ }
fwrite(outbuf, 1, outlen, out);
fclose(out);
return 1;