Added: ndbuf_free_item() function to free in a proper way e.g.

free allocated stuff via escan function.
This commit is contained in:
Alexander Vdolainen 2018-09-17 20:29:03 +03:00
parent fb41052802
commit 68aa01d300
2 changed files with 20 additions and 0 deletions

View File

@ -178,4 +178,7 @@ int ndbuf_cmp(ndbuf_t *, ndbuf_t *);
*/
int ndbuf_memopt(ndbuf_t *);
/* free in a right way: freing allocated memory during escan */
void ndbuf_free_item(ndbuf_t *b, void *ip, size_t is);
#endif /* __NDBUF_H__ */

17
ndbuf.c
View File

@ -913,4 +913,21 @@ int ndbuf_memopt(ndbuf_t *b)
return 0;
}
void ndbuf_free_item(ndbuf_t *b, void *ip, size_t is)
{
if(!b || !ip) return;
if(__is_moless(b->flags)) return;
if(__is_usermo(b->flags)) {
if((b->flags & NDBUF_BURN) && (is > 0)) b->mop->zero(ip, is);
b->mop->free(ip);
} else {
if((b->flags & NDBUF_BURN) && (is > 0)) memset(ip, 0, is);
free(ip);
}
return;
}
#undef DEFAULT_PREALLOC_SIZE