Implement memory management TODOs
[centaur.git] / src / elfucli.c
index cd8f0baa378d618dba1a2076e86706348ec124e1..b01c91a1c6992aecac7fbce4e5ec890eca20912c 100644 (file)
@@ -84,6 +84,10 @@ int main(int argc, char **argv)
         }
         break;
       case 'i':
+        if (me) {
+          elfu_mElfDestroy(me);
+        }
+
         printf("Opening input file %s.\n", optarg);
         openElf(&hIn, optarg, ELF_C_READ);
         if (!hIn.e) {
@@ -145,9 +149,18 @@ int main(int argc, char **argv)
             goto ERR;
           } else {
             printf("--reladd: Injecting %s...\n", optarg);
-            elfu_mCheck(mrel);
-            elfu_mReladd(me, mrel);
+            if (elfu_mCheck(mrel)) {
+              printf("--reladd: Check for input file failed.\n");
+              elfu_mElfDestroy(mrel);
+              goto ERR;
+            }
+            if (elfu_mReladd(me, mrel)) {
+              printf("--reladd: Failed.\n");
+              elfu_mElfDestroy(mrel);
+              goto ERR;
+            }
             printf("--reladd: Injected %s.\n", optarg);
+            elfu_mElfDestroy(mrel);
           }
         }
         break;
@@ -200,6 +213,10 @@ int main(int argc, char **argv)
 
 
 EXIT:
+  if (me) {
+    elfu_mElfDestroy(me);
+  }
+
   if (hIn.e) {
     closeElf(&hIn);
   }