On Tue, 2003-12-09 at 05:40, Marco Morandini wrote: > This patch should take care of the > > "delete of something allocated with new[]" > > part of > > http://opendx.watson.ibm.com/dx/mailArchives/mails.html/opendx-dev.0310/msg00005.html > > > Regards, > > Marco Morandini > ---- > OK, I applied these patches. I think code changes like these, that address new and new[] matching up with delete and delete[] are not worthwhile. Although they're fine changes, the places where the code uses delete on the output of (something like) DuplicateString() are so numerous that it would take probably a dozen changes in every source file to fix.
I think Dave T. said something about making some of these changes due compilation issues. I don't remember if he said it was an error or a warning he was dealing with but he seemed to have a good reason to make the change. But, I wouldn't make these changes if the purpose is to address runtime warnings. In short, the code ought to be different but changing it is a lot of buck for no bang. The ui code routinely does things like the following: char* ptr = new char[10]; . . . delete ptr; ...and other types show up there also, int, void*, whatever. We just have to count on that working. I've never seen it not work. It would certainly be wrong to instantiate an array of objects and use delete to get rid of them because that wouldn't call the destructor for each object. ...but I think the dxui code never instantiates arrays of objects as in Base* bPtr = new Base[10]; (I'm overloading the definition of "never" to mean probably not at all but even if there is such a situation, the deletion is handled correctly.) Sort of on this topic, the code provides implementations of new and delete operators (although not new[] and delete[] operators). I had thought that they should go away although I saw that we sometimes realloc the output of new (which is defined as malloc). So I guess I would leave it alone until there is a compelling reason to change it. But there won't ever be one. Attached is a valgrind suppressions file that (I think) does a good job on the delete/delete[] warnings:
##----------------------------------------------------------------------## # Errors to suppress by default for glibc 2.1.3 # Format of this file is: # { # name_of_suppression # kind: one of Param Value1 Value2 Value4 Value8 # Free Addr1 Addr2 Addr4 Addr8 # Cond (previously known as Value0) # (if Param: name of system call param, if Free: name of free-ing fn) # caller0 name, or /name/of/so/file.so # caller1 name, or ditto # (optionally: caller2 name) # (optionally: caller3 name) # } #-------- Suppress errors appearing as a result of calling #-------- __libc_freeres() { Mismatched free() / delete / delete [](Free) Free fun:*free* fun:* } { Mismatched free() / delete / delete [](Free) Free fun:*realloc* fun:* }