summaryrefslogtreecommitdiff
path: root/nuttx/binfmt/libelf/libelf_uninit.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/binfmt/libelf/libelf_uninit.c')
-rw-r--r--nuttx/binfmt/libelf/libelf_uninit.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/nuttx/binfmt/libelf/libelf_uninit.c b/nuttx/binfmt/libelf/libelf_uninit.c
index e5fa2e6c3..06bb89681 100644
--- a/nuttx/binfmt/libelf/libelf_uninit.c
+++ b/nuttx/binfmt/libelf/libelf_uninit.c
@@ -42,8 +42,12 @@
#include <unistd.h>
#include <debug.h>
#include <errno.h>
+
+#include <nuttx/kmalloc.h>
#include <nuttx/binfmt/elf.h>
+#include "libelf.h"
+
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
@@ -75,6 +79,12 @@
int elf_uninit(struct elf_loadinfo_s *loadinfo)
{
+ /* Free all working buffers */
+
+ elf_freebuffers(loadinfo);
+
+ /* Close the ELF file */
+
if (loadinfo->filfd >= 0)
{
close(loadinfo->filfd);
@@ -83,3 +93,43 @@ int elf_uninit(struct elf_loadinfo_s *loadinfo)
return OK;
}
+/****************************************************************************
+ * Name: elf_freebuffers
+ *
+ * Description:
+ * Release all working buffers.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_freebuffers(struct elf_loadinfo_s *loadinfo)
+{
+ /* Release all working allocations */
+
+ if (loadinfo->shdr)
+ {
+ kfree((FAR void *)loadinfo->shdr);
+ loadinfo->shdr = NULL;
+ }
+
+#ifdef CONFIG_ELF_CONSTRUCTORS
+ if (loadinfo->ctors)
+ {
+ kfree((FAR void *)loadinfo->ctors);
+ loadinfo->ctors = NULL;
+ loadinfo->nctors = 0;
+ }
+#endif
+
+ if (loadinfo->iobuffer)
+ {
+ kfree((FAR void *)loadinfo->iobuffer);
+ loadinfo->iobuffer = NULL;
+ loadinfo->buflen = 0;
+ }
+
+ return OK;
+}