bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Gettext: Suggested addition of memory allocation clean-up in 'intl' libr


From: Svante Seleborg
Subject: Gettext: Suggested addition of memory allocation clean-up in 'intl' library
Date: Wed, 16 Nov 2005 20:18:25 +0100

Hello,
 
In gettext 0.14.5, there is no way to explicitly request deallocation of
allocated memory.
 
I'd like to suggest and discuss a design to fix this issue, and I may be
willing to make the implementation after the maintainer and other readers of
the list agree with a design for this change.

There are three places in the existing code where clean-up is performed,
apparently at program exit, when _LIBC is #defined:

dcigettext.c:

#ifdef _LIBC
/* If we want to free all resources we have to do some work at
   program's end.  */
libc_freeres_fn (free_mem)
...
#endif

and

finddomain.c:
#ifdef _LIBC
libc_freeres_fn (free_mem)
{
...
#endif

Finally

in

localealias.c:

libc_freeres_ptr (static char *string_space);
...
libc_freeres_ptr (static struct alias_map *map);

---

I have not verified that these calls actually suffice to free all
allocations, but this might be a good way to find out...

---

I've not been able to find any documentation for the libc_freeres_ptr and
libc_freeres_fn macros, but some source fragements and their usages seems to
imply that they implement atexit()-style functionality, without an explicit
call. Just why atexit() is not used is not apparent - that should be
portable enough, but there may well be a good reason that I don't know
about. Perhaps a kind soul could point to a place in space and time where
this is documented? (And no, Google does not appear to help much.)

I'd like to start the discussion by proposing some different possible
strategies, in descending order of personal preference:

1 - Use atexit instead of libc_xxx like above, and change the code to
reflect this even in the absence of _LIBC. The atexit-registration is
performed conditionally upon first entry to any function that allocates
memory, i.e. something like:

extern int atexit_is_registred;
extern void free_all_memory(void);

...

if (!atexit_is_registred) {
    atexit_is_registred = atexit(free_all_memory);
}

2 - Introduce a new call, i.e. 'free_all_memory', and have the caller call
this whenever appropriate. This of course invalidates all the callers
pointers to texts etc, so it's not trivial to use. It does have the
advantage that memory can be reclaimed without restarting the program, a
definite advantage in long running server processes and other cases such as
an interactive language switch. In fact - it'd be nice if this was in
_addition_ to option 1. The semantics of free_all_memory would of course be
that it's ok to call any number of times - just don't use any pointers
returned from any other call afterwards.

3 - Change the semantics of one of the existing calls to special case a
situation of for example a domain name == "" to cause a call of
'free_all_memory'.

I'd like to propose 1+2.

Comments, discussion, corrections, additional ideas? No flames please.

Svante






reply via email to

[Prev in Thread] Current Thread [Next in Thread]