shithub: scc

Download patch

ref: cc8fd34873b779bedd6d54445fae80e3fb27ce13
parent: f8fbc1dd568bb33610e5f11ac459d58476eb0643
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 23 12:32:41 EDT 2019

[ld] Don't alloc object before testing

If the object type is wrong then we have to free the object,
so it is better to check the type before allocating th ememory.

--- a/src/cmd/ld/pass1.c
+++ b/src/cmd/ld/pass1.c
@@ -174,18 +174,18 @@
 {
 	Obj *obj;
  
-	if ((obj = objnew(type)) == NULL) {
-		error("out of memory");
-		return;
-	}
-
 	if (bintype != -1 && bintype != type) {
 		error("not compatible object file");
-		goto delete;
+		return;
 	}
 	bintype = type;
 	binops = obj->ops;
- 
+
+	if ((obj = objnew(type)) == NULL) {
+		error("out of memory");
+		return;
+	}
+
 	if ((*binops->read)(obj, fp) < 0) {
 		error("object file corrupted");
 		goto delete;