mismatched free/delete in typeregister.h
Milian Wolff
mail at milianw.de
Mon May 30 14:43:58 UTC 2011
David Nolden, 30.05.2011:
> 2011/5/30 Milian Wolff <mail at milianw.de>:
> > David Nolden, 29.05.2011:
> >> 2011/5/28 Christoph Bartoschek <bartoschek at gmx.de>:
> >> > Hi
> >> >
> >> > abstracttype.h:254 has the line
> >> >
> >> > return *new (new char[size]) DataType(rhs);
> >> >
> >> > Here one first allocates size bytes with new[]. Into the allocated
> >> > space a new DataType object is created by using placement new.
> >> > Placement new gets a pointer to a memory location and creates the
> >> > object there instead of fetching memory internally. The syntax is:
> >> >
> >> > new (pointer) T();
> >> >
> >> > This is also used in typeregister.h. In line 99 however the memory is
> >> > freed with
> >> >
> >> > delete temp;
> >> >
> >> > Valgrind complains because delete cannot be used for memory that was
> >> > allocated with new []. Instead one has to use delete []. Therefore the
> >> > correct code in line 99 should be:
> >> >
> >> > delete [] reinterpret_cast<char *>(temp);
> >>
> >> This is right, it is deallocated like this in other places, and should
> >> be deallocated here in the same way.
> >>
> >> > The cast is necessary because the memory was allocated as a char
> >> > array.
> >> >
> >> > There is one problem with the code: The destructor of the DataType is
> >> > not called. Therefore the solution is:
> >> >
> >> > temp->~Data();
> >> >
> >> > delete [] reinterpret_cast<char *>(temp);
> >>
> >> Yes, this call should be added too.
> >
> > will you fix this or should I do that?
>
> I've already done it.
Ah ok, you must have forgotten to git push though as I cannot see your commit
yet.
bye
--
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20110530/92230040/attachment.sig>
More information about the KDevelop-devel
mailing list