gconv_close.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Release any resource associated with given conversion descriptor.
  2. Copyright (C) 1997-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <stdlib.h>
  16. #include <gconv_int.h>
  17. int
  18. __gconv_close (__gconv_t cd)
  19. {
  20. struct __gconv_step *srunp;
  21. struct __gconv_step_data *drunp;
  22. size_t nsteps;
  23. /* Free all resources by calling destructor functions and release
  24. the implementations. */
  25. srunp = cd->__steps;
  26. nsteps = cd->__nsteps;
  27. drunp = cd->__data;
  28. do
  29. {
  30. if (!(drunp->__flags & __GCONV_IS_LAST) && drunp->__outbuf != NULL)
  31. free (drunp->__outbuf);
  32. }
  33. while (!((drunp++)->__flags & __GCONV_IS_LAST));
  34. /* Free the data allocated for the descriptor. */
  35. free (cd);
  36. /* Close the participating modules. */
  37. return __gconv_close_transform (srunp, nsteps);
  38. }