Article View: comp.std.c++
Article #2297Re: auto_ptr: : reset and auto_ptr::operator=
From: Eric Biederman
Date: Wed, 25 Oct 1995 02:39
Date: Wed, 25 Oct 1995 02:39
27 lines
1875 bytes
1875 bytes
Someone writes: >Actually, it occurs to me that the following does work: > > auto_ptr< T > f() ; > auto_ptr< T > p1( f().release() ) ; > auto_ptr< T > p2 ; > p2.reset( f().release() ) ; > >Somehow, it just doesn't seem natural, though. There is a case where it doesn't work. The problem is that you are passing it as a standard pointer type. What happens if you were to run out of stack after the call to release and before the call to the constructor, or reset. And an exception is thrown. If your program actualy catches that exception then a memory leak has occured. ( A rare case I will admit). There are probably more realistic examples is less mundane code. It must be in an object at all times TO BE SAFE! --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<EBIEDERM.95Oct24164938@cse.unl.edu>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<199509111753.AA15077@xs1.xs4all.nl> <MATT.95Sep22101332@physics11.Berkeley.EDU> <9527400.19710@mulga.cs.mu.OZ.AU> <9510022022.AA18434@mailserv.taligent.com> <DFv3F0.DCr@akropolis.malmo.trab.se> <44thrj$kid@gabi.gabi-soft.fr> <9529510.24230@mulga.cs.mu.OZ.AU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 25 Oct 95 02:39:37 GMT Approved: fjh@cs.mu.oz.au From: ebiederm@cse.unl.edu (Eric Biederman) Newsgroups: comp.std.c++ Subject: Re: auto_ptr: : reset and auto_ptr::operator= X-Original-Date: 24 Oct 1995 21:49:38 GMT Organization: University of Nebraska--Lincoln Message-ID: <EBIEDERM.95Oct24164938@cse.unl.edu> References: <199509111753.AA15077@xs1.xs4all.nl> <MATT.95Sep22101332@physics11.Berkeley.EDU> <9527400.19710@mulga.cs.mu.OZ.AU> <9510022022.AA18434@mailserv.taligent.com> <DFv3F0.DCr@akropolis.malmo.trab.se> <44thrj$kid@gabi.gabi-soft.fr> <9529510.24230@mulga.cs.mu.OZ.AU> In-Reply-To: fjh@munta.cs.mu.OZ.AU's message of 22 Oct 1995 07:03:18 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMI2jwuEDnX0m9pzZAQFanQF/R0TIj6M9eaDqU/jalwt8NS8zd/nX/4lC Bc6ijcPz8H1Ws9WXayTy4tJ3+eu0zBR2 =P95U