[openssl-dev] [eng_rdrand] alloc and free
Richard Levitte
levitte at openssl.org
Fri Jan 22 00:20:54 UTC 2016
In message <DB5PR04MB1302BB3B91A8955DC8BB1DCFEEC30 at DB5PR04MB1302.eurprd04.prod.outlook.com> on Thu, 21 Jan 2016 10:57:19 +0000, Catalin Vasile <cata.vasile at nxp.com> said:
cata.vasile> ENGINE_load_rdrand() creates a new engine, it adds
cata.vasile> it/registers it and then frees it. Looking further into
cata.vasile> these functions, the registration does NOT create a new
cata.vasile> object and then copy the data into it, so the
cata.vasile> registration is based on an object that it's later
cata.vasile> released.
Welllll.... not quite! Pointers to engines aren't merely pointers,
they are more like handles and have reference counters. So, the
called `ENGINE *toad = ENGINE_rdrand()' will create the reference to a
new ENGINE object, that is correct. Three lines later, the call
`ENGINE_add(toadd)' will create a new reference to the same object, by
incrementing the reference counter, and will store the pointer to the
object in OpenSSL's internal list. The following call
`ENGINE_free(toadd)' simply decrements the reference counter (from 2
to 1) but does not actually free the object (that would require
another ENGINE_free).
Does that make it clearer? For further info, may I suggest you do
`perldoc doc/crypto/engine.pod', and most specifically read the
section titled "Reference counting and handles"?
Cheers,
Richard
--
Richard Levitte levitte at openssl.org
OpenSSL Project http://www.openssl.org/~levitte/
More information about the openssl-dev
mailing list