I believe I read somewhere in the obscure Crypto++ documentation, what there is of it, that whenever you pass a pointer as an argument to a constructor that new object now "owns" the object that the pointer refers to and will delete it when that object is itself deleted.

If you pass a reference to a constructor, then you still own the object.

So you shouldn't delete "f" because "h" deleted it in its destructor.

Dan Sanderson
Living Software




<-----Original Message----->
From: glokomov
Sent: 8/12/2004 4:17:46 AM
To: [EMAIL PROTECTED]
Subject: Strange crash




Sorry for the double post, I forgot the subject...


>
Hi to every,
>
I'm trying to use the CryptoPP library yet I 'm facing strange crashes...
>

>
Here follows my code:
>

>
int main(int argc, char* argv[]) throw ()
>
{
>

>
AutoSeededRandomPool rng;
>
RSA::PrivateKey privKey;
>

>
privKey.Initialize(rng,256);
>

>
FileSink *f;
>
HexEncoder *h;
>

>
f=new FileSink("c:\\a.der");
>

>
h=new HexEncoder(f);
>

>
privKey.DEREncode(h->Ref()); // (or *h)
>
h->MessageEnd();
>
f->MessageEnd();
>

>
delete h;
>
delete f; // <--- ERROR: ACCESS VALIDATION
>

>
return 1;
>
}
>

>
I'm using Visual C++ 6 with SP6, CryptoPP version 5.21 linked as a static library.
>
When I run the program it gives me access violation error on the "delete f", yet the program does write the file with the key encoded as an hex string.
>
If I remove that line all works perfectly... Can anyone give me some clues.
>
Thanks anticipately.
>

>
Bye,
>
Federico.
>

>

>

>

>
.
>

_______________________________________________________________
Get the FREE email that has everyone talking at http://www.mail2world.com

 

Reply via email to