On 03/15/2012 03:27 PM, Rod wrote: > Most of the Crypto++ examples invoke "new" inside a constructor call, > which doesn't allow a corresponding "delete" to be called. Does this cause a > memory leak? > > Example: > StringSource(pMessage, nMessageSize, true, new > StreamTransformationFilter(aes, new StringSink(sEncryptedSegment))); > > The code above works, but I was unsure about a memory leak, so I tried > putting things on the stack: > > StringSink oSink(sEncryptedSegment); StreamTransformationFilter oFilter(aes, > &oSink); StringSource(pMessage, nMessageSize, true, &oFilter); > > The revised code crashes with a segmentation fault. > > Is there a memory leak with the first form above? If so, how should it be > revised to avoid that? Thanks. > > Rod >
I have not read the source, but from your eksample it is clear the Stringsource expects to "own" the passed StreamTransformationFilter object and deletes it in its own destruktor. Likewise the StreamTransformationFilter expects to "own" the StringSink object. The error in the second example arises from the Stringsource trying to delete an object on the stack. Best regards KenR -- 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.
