Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » [Solved] Any::dtor fails after it is picked
[Solved] Any::dtor fails after it is picked [message #19137] Fri, 14 November 2008 19:14 Go to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

testcase:
Any aa;
ArrayMap<unsigned, Any> am; //just something to pick aa
am.AddPick(0,aa);//aa is now picked
//and we have exception when aa is to be destroyed 


cause:
The cause is internal Pick behaviour and Clear() member function. When object is picked, it`s internal ptr is set to (void *)1. When object is to be destroyed, it`s Clear() is called. But Clear() doesn`t check if ptr == (void *)1. It just checks if ptr is nonzero. What we have? Of course exception on trying to delete (*1);

proposal:
Change Clear() function to something like
	void Clear()                                  { if(ptr && !IsPicked()) delete ptr; ptr = NULL; }

[Updated on: Fri, 14 November 2008 22:48]

Report message to a moderator

Re: [BUG?] Any::dtor fails after it is picked [message #19140 is a reply to message #19137] Fri, 14 November 2008 21:21 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Mindtraveller wrote on Fri, 14 November 2008 13:14

testcase:
Any aa;
ArrayMap<unsigned, Any> am; //just something to pick aa
am.AddPick(0,aa);//aa is now picked
//and we have exception when aa is to be destroyed 


cause:
The cause is internal Pick behaviour and Clear() member function. When object is picked, it`s internal ptr is set to (void *)1. When object is to be destroyed, it`s Clear() is called. But Clear() doesn`t check if ptr == (void *)1. It just checks if ptr is nonzero. What we have? Of course exception on trying to delete (*1);

proposal:
Change Clear() function to something like
	void Clear()                                  { if(ptr && !IsPicked()) delete ptr; ptr = NULL; }



Thanks, correct observation, fixed.

Mirek
Previous Topic: Vector::SetCount()
Next Topic: streaming [FEATURE REQUEST]
Goto Forum:
  


Current Time: Thu Mar 28 11:26:40 CET 2024

Total time taken to generate the page: 0.01436 seconds