I have a fairly simple example that is showing
Code: Select all
free(): double free detected in tcache 2
error that aborts with a core dump.
I am instantiating the objects like this:
Code: Select all
'---- main
dim dt as dataobj
dt = dataobj("54")
print "Press key to end ..."
sleep
Code: Select all
dim as dataobj dt = dataobj("54")
The full code is:
Code: Select all
const null = 0
type dataobj
private:
datstring as zstring ptr
declare sub destroy ()
public:
declare constructor ()
declare constructor (k as string)
declare destructor ()
end type
sub dataobj.destroy()
'deallocate datstring if present and set ptr to null.
if this.datstring <> null then
deallocate this.datstring
this.datstring = null
end if
end sub
constructor dataobj ()
'print "constructor dataobj no params"
datstring = null
end constructor
'constructor for key datstring
constructor dataobj (k as string)
destroy
dim as integer l = len(k)
If l > 0 then
datstring = allocate(l + 1)
*datstring = k
else
datstring = null
end if
end constructor
destructor dataobj ()
destroy
end destructor
'---- main
dim dt as dataobj
dt = dataobj("54")
print "Press key to end ..."
sleep