commit bc4f2cc0140a35b3aab00f14c801e96a6c21dd04
parent 2782643fbc96110d970f5842330c214569a6678b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 23 Aug 2019 16:32:41 +0100
[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.
Diffstat:
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/cmd/ld/pass1.c b/src/cmd/ld/pass1.c
@@ -174,18 +174,18 @@ newobject(FILE *fp, int type, int inlib)
{
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;