gconv: Check reference count in __gconv_release_cache [BZ #24677]

This fixes a regression introduced in commit
7e740ab2e7 ("libio: Fix gconv-related
memory leak [BZ #24583]").

__gconv_release_cache is only ever called with heap-allocated
arrays which contain at least one member.  The statically allocated
ASCII steps are filtered out by __wcsmbs_close_conv.
This commit is contained in:
Florian Weimer 2019-07-18 17:27:24 +02:00
parent 7e681561a3
commit 50ce3eae5b
2 changed files with 12 additions and 3 deletions

View File

@ -1,3 +1,9 @@
2019-07-25 Florian Weimer <fweimer@redhat.com>
[BZ #24677]
* iconv/gconv_cache.c (__gconv_release_cache): Check reference
counter before freeing array.
2019-07-24 H.J. Lu <hongjiu.lu@intel.com> 2019-07-24 H.J. Lu <hongjiu.lu@intel.com>
[BZ #24603] [BZ #24603]

View File

@ -446,9 +446,12 @@ __gconv_lookup_cache (const char *toset, const char *fromset,
void void
__gconv_release_cache (struct __gconv_step *steps, size_t nsteps) __gconv_release_cache (struct __gconv_step *steps, size_t nsteps)
{ {
if (gconv_cache != NULL) /* The only thing we have to deallocate is the record with the
/* The only thing we have to deallocate is the record with the steps. But do not do this if the reference counter is still
steps. */ positive. This can happen if the steps array was cloned by
__wcsmbs_clone_conv. (The array elements have separate __counter
fields, but they are only out of sync temporarily.) */
if (gconv_cache != NULL && steps->__counter == 0)
free (steps); free (steps);
} }