@@ -131,6 +131,11 @@ int main(int argc, char **argv)
131131 display_openssl_errors (__LINE__ );
132132 exit (1 );
133133 }
134+ /*
135+ * ENGINE_init() returned a functional reference, so free the structural
136+ * reference from ENGINE_by_id().
137+ */
138+ ENGINE_free (e );
134139
135140 if (key_pass && !ENGINE_ctrl_cmd_string (e , "PIN" , key_pass , 0 )) {
136141 display_openssl_errors (__LINE__ );
@@ -160,7 +165,6 @@ int main(int argc, char **argv)
160165
161166 /* Encrypt the data */
162167 pkey_ctx = EVP_PKEY_CTX_new (public_key , e );
163-
164168 if (pkey_ctx == NULL ) {
165169 fprintf (stderr , "Could not create context\n" );
166170 display_openssl_errors (__LINE__ );
@@ -186,6 +190,7 @@ int main(int argc, char **argv)
186190 }
187191
188192 EVP_PKEY_CTX_free (pkey_ctx );
193+ EVP_PKEY_free (public_key );
189194
190195 printf ("Data encrypted\n" );
191196
@@ -230,6 +235,7 @@ int main(int argc, char **argv)
230235 }
231236
232237 EVP_PKEY_CTX_free (pkey_ctx );
238+ EVP_PKEY_free (private_key );
233239
234240 /* Compare output */
235241
@@ -242,6 +248,7 @@ int main(int argc, char **argv)
242248 exit (1 );
243249 }
244250
251+ /* Free the functional reference from ENGINE_init */
245252 ENGINE_finish (e );
246253 CONF_modules_unload (1 );
247254 return 0 ;
0 commit comments