On Thursday, November 14, 2013 2:53:32 PM UTC-5, Marshall Clow wrote: > > > On Nov 14, 2013, at 9:36 AM, Jeffrey Walton <[email protected]<javascript:>> > wrote: > > > On Monday, November 4, 2013 12:10:18 PM UTC-5, Arendell wrote: >> >> MD5 hash; >>> byte buffer[2 * MD5::DIGESTSIZE]; >>> >>> FileSource f(argv[1], true, >>> new HashFilter(hash, >>> new HexEncoder(new ArraySink(buffer,2 * MD5::DIGESTSIZE)))); >>> >>> >> Is this way cause a memory leak? >> > No. > > From Readme.txt: > > *** Important Usage Notes *** > > 1. If a constructor for A takes a pointer to an object B (except primitive > types such as int and char), then A owns B and will delete B at A's > destruction. If a constructor for A takes a reference to an object B, > then the caller retains ownership of B and should not destroy it until > A no longer needs it. > > > That's all well and good, but I think that the OP's question was more > along the line of th following scenario: > 1) Attempt to allocate and create ArraySink(buffer,2 * MD5::DIGESTSIZE) > succeeds. > 2) Attempt to allocate and create HexEncoder() succeeds > 3) Attempt to allocate and create HashFilter throws. (say, when operator > new fails to allocate memory) >
Oh, I was not looking at exception safety. Usually that question relates to a memory leak because delete is not called on the attached HexEncoder or ArraySink. I'm not sure what happens in the case of an exception. std:swap is usually not used, so the worst possible outcome is probably going to occur - both a memory leak and inconsistent state. Jeff -- -- You received this message because you are subscribed to the "Crypto++ Users" Google Group. To unsubscribe, send an email to [email protected]. More information about Crypto++ and this group is available at http://www.cryptopp.com. --- You received this message because you are subscribed to the Google Groups "Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
