On Sunday, 3 February 2019 18:17:00 CET Mark Feit wrote:
> (This has been split off from the static code analysis thread since it's
> a different topic.)
> 
> I've completed the first cut of an overhaul of the use of dynamic memory
> allocation in the source tree with an eye toward safety and an eventual
> place to do a clean shutdown (closing the database, removing locks, etc.).
> 
> 
> What was done:
> 
> Malloc(), calloc(), realloc(), strdup() and strndup() have been made
> fail-safe through counterparts named dt_*() which exit cleanly through a
> common function.  The new versions are in the utilities.h header as
> short static inline functions that, on failure, call an error function
> in utilities.c.  This arrangement seems subjectively faster than a
> straight-up function call and doesn't pepper copies of the same static
> strings all over the object files.  If any functions have been missed,
> please point them out.
> 
> Calls to free() have been changed to dt_free(), which is currently a
> pass-through to free().
> 
> dt_alloc_align() and dt_free_align() have been given the same treatment
> and renamed to dt_malloc_aligned() and dt_free_aligned() for name
> consistency with the other functions.

Thanks for your work.

If you want to change allocations anyway, you should really take a look at 
talloc [1]. talloc is a hierarchical, reference counted memory pool system 
with destructors. If you free the top memory context all children will be 
freed to. It is just fun working with it and memory leaks don't really happen 
anymore. If you forget to free some memory it will be gone once the parent is 
freed. Also you can print the memory allocation tree for inspection.

Just my 2 cents.

Cheers,


        Andreas

[1] https://talloc.samba.org/talloc/doc/html/index.html


___________________________________________________________________________
darktable developer mailing list
to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org

Reply via email to