[2016-03-14 09:29] m...@mmmmarascio.xyz > scrīpsit markus schnalke <mei...@marmaro.de>: > > > [2016-03-13 12:46] m...@mmmmarascio.xyz > > > > > > As suggested, the attached patch changes calls to mh_xmalloc() into calls > > > to mh_xcalloc(). > > > > If feasable, I would suggest, to apply the changes in two commits: > > > > 1) replace mh_xmalloc() with mh_xcalloc() > > 2) remove the casts > > Thanks for the feedback. The attached patch accomplishes the first of > these two suggested commits. It leaves existing casts alone and it leaves > the parentheses used with sizeof alone.
Thanks for the work, it's committed. Do you have a patch, which removes the casts? [2016-03-13 12:46] m...@mmmmarascio.xyz > > But I don't understand the idea of an mh_xfree(void **). Would you mind > explaining the idea further? Would the mh_xfree() be used everywhere > instead of free()? If I understand more, I may be able to complete the task. After a discussion with Markus we have decided to call this function better mh_free0(void *). The idea is to have a function which not only frees the memory, it should also set the pointer to NULL. An example implementation is attached. With this function following code should run without a problem: char *ptr = mh_xcalloc(42, sizeof(char *)); //do work mh_free0(&ptr); assert(ptr == NULL); Philipp
#include <stdlib.h> void mh_free0(void *ptr) { void **pointer = ptr; free(*pointer); *pointer = NULL; }
pgptbNr9ULvPB.pgp
Description: PGP signature