GPLv2 release
[centaur.git] / src / elfucli.c
index cd8f0baa378d618dba1a2076e86706348ec124e1..f6bac3fcd7314469f05d6d16b018154293f762e4 100644 (file)
@@ -1,3 +1,18 @@
+/* This file is part of centaur.
+ *
+ * centaur is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License 2 as
+ * published by the Free Software Foundation.
+
+ * centaur is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with centaur.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -84,6 +99,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 +164,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 +228,10 @@ int main(int argc, char **argv)
 
 
 EXIT:
+  if (me) {
+    elfu_mElfDestroy(me);
+  }
+
   if (hIn.e) {
     closeElf(&hIn);
   }