diff --git a/src/keys.c b/src/keys.c index 28ddb98..3ce4cdd 100644 --- a/src/keys.c +++ b/src/keys.c @@ -12,6 +12,7 @@ SEXP R_parse_der_pubkey(SEXP input){ bail(!!pkey); unsigned char *buf = NULL; int len = i2d_PUBKEY(pkey, &buf); + EVP_PKEY_free(pkey); bail(len); SEXP res = allocVector(RAWSXP, len); memcpy(RAW(res), buf, len); @@ -26,6 +27,7 @@ SEXP R_parse_der_key(SEXP input){ bail(!!pkey); unsigned char *buf = NULL; int len = i2d_PrivateKey(pkey, &buf); + EVP_PKEY_free(pkey); bail(len); SEXP res = allocVector(RAWSXP, len); memcpy(RAW(res), buf, len); @@ -39,6 +41,7 @@ SEXP R_parse_der_cert(SEXP input){ bail(!!cert); unsigned char *buf = NULL; int len = i2d_X509(cert, &buf); + X509_free(cert); bail(len); SEXP res = allocVector(RAWSXP, len); memcpy(RAW(res), buf, len); @@ -54,6 +57,7 @@ SEXP R_derive_pubkey(SEXP input){ bail(!!pkey); unsigned char *buf = NULL; int len = i2d_PUBKEY(pkey, &buf); + EVP_PKEY_free(pkey); bail(len); SEXP res = allocVector(RAWSXP, len); memcpy(RAW(res), buf, len); @@ -67,9 +71,11 @@ SEXP R_cert_pubkey(SEXP input){ X509 *cert = d2i_X509(NULL, &ptr, LENGTH(input)); bail(!!cert); EVP_PKEY *key = X509_get_pubkey(cert); + X509_free(cert); bail(!!key); unsigned char *buf = NULL; int len = i2d_PUBKEY(key, &buf); + EVP_PKEY_free(key); bail(len); SEXP res = allocVector(RAWSXP, len); memcpy(RAW(res), buf, len); diff --git a/src/pem.c b/src/pem.c index e0a60ea..9771f7b 100644 --- a/src/pem.c +++ b/src/pem.c @@ -43,6 +43,7 @@ SEXP R_parse_pem_key(SEXP input, SEXP password){ bail(!!pkey); unsigned char *buf = NULL; int len = i2d_PrivateKey(pkey, &buf); + EVP_PKEY_free(pkey); bail(len); SEXP res = allocVector(RAWSXP, len); memcpy(RAW(res), buf, len); @@ -57,6 +58,7 @@ SEXP R_parse_pem_pubkey(SEXP input){ bail(!!pkey); unsigned char *buf = NULL; int len = i2d_PUBKEY(pkey, &buf); + EVP_PKEY_free(pkey); bail(len); SEXP res = allocVector(RAWSXP, len); memcpy(RAW(res), buf, len); @@ -69,6 +71,7 @@ SEXP R_parse_pem_cert(SEXP input){ X509 *cert = PEM_read_bio_X509(mem, NULL, password_cb, NULL); unsigned char *buf = NULL; int len = i2d_X509(cert, &buf); + X509_free(cert); bail(len); SEXP res = allocVector(RAWSXP, len); memcpy(RAW(res), buf, len); @@ -83,6 +86,7 @@ SEXP R_parse_pem_pubkey_pkcs1(SEXP input){ bail(!!rsa); unsigned char *buf = NULL; int len = i2d_RSA_PUBKEY(rsa, &buf); + RSA_free(rsa); bail(len); SEXP res = allocVector(RAWSXP, len); memcpy(RAW(res), buf, len);