shithub: scc

Download patch

ref: 5ee2e8b13124750a58dc720afbc16d4d0a6f71f4
parent: e60e6dc4ded6d0ff578610e39d7a8c8a6f62f3ed
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Oct 30 07:16:41 EDT 2021

libmach: Add elf64del()

This function free all the memory used by an elf64 object file.

--- a/src/libmach/deps.mk
+++ b/src/libmach/deps.mk
@@ -53,6 +53,9 @@
 elf64/elf64.o: $(INCDIR)/scc/scc/mach.h
 elf64/elf64.o: elf64/../libmach.h
 elf64/elf64.o: elf64/elf64.h
+elf64/elf64del.o: $(INCDIR)/scc/scc/mach.h
+elf64/elf64del.o: elf64/../libmach.h
+elf64/elf64del.o: elf64/elf64.h
 elf64/elf64new.o: $(INCDIR)/scc/scc/mach.h
 elf64/elf64new.o: elf64/../libmach.h
 elf64/elf64new.o: elf64/elf64.h
--- a/src/libmach/elf64/elf64.c
+++ b/src/libmach/elf64/elf64.c
@@ -13,7 +13,7 @@
 	.setidx = NULL,
 	.pc2line = NULL,
 	.strip = NULL,
-	.del = NULL,
+	.del = elf64del,
 	.write = NULL,
 	.getsym = NULL,
 	.getsec = NULL,
--- /dev/null
+++ b/src/libmach/elf64/elf64del.c
@@ -1,0 +1,23 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <scc/mach.h>
+
+#include "../libmach.h"
+#include "elf64.h"
+
+void
+elf64del(Obj *obj)
+{
+        struct elf64 *elf = obj->data;
+
+        if (elf) {
+                free(elf->phdr);
+                free(elf->shdr);
+		free(elf->syms);
+                free(elf->strtbl[0]);
+                free(elf->strtbl[1]);
+        }
+        free(obj->data);
+        obj->data = NULL;
+}
--- a/src/libmach/elf64/rules.mk
+++ b/src/libmach/elf64/rules.mk
@@ -3,3 +3,4 @@
 	elf64/elf64new.o\
 	elf64/elf64probe.o\
 	elf64/elf64read.o\
+	elf64/elf64del.o\