aboutsummaryrefslogtreecommitdiffstats
path: root/edify
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2010-02-17 18:31:48 -0800
committerKenny Root <kroot@google.com>2010-02-17 18:33:44 -0800
commit21854ccdb250e6e81311b4317934e8c953b252a8 (patch)
treee6f8048de230914aaaf65f7ddb72a41b460b4ac9 /edify
parent2e068dc33053970c2d58984ee182058bdac950db (diff)
downloadbootable_recovery-21854ccdb250e6e81311b4317934e8c953b252a8.zip
bootable_recovery-21854ccdb250e6e81311b4317934e8c953b252a8.tar.gz
bootable_recovery-21854ccdb250e6e81311b4317934e8c953b252a8.tar.bz2
Filename check and free allocated strings
Make sure file is valid before we try to read it. Also free all the strings we allocate in various functions so we don't leak memory. Change-Id: Ica3c8dae992e73718c79c12ff5d7e315c290caea
Diffstat (limited to 'edify')
-rw-r--r--edify/expr.c3
-rw-r--r--edify/main.c4
2 files changed, 7 insertions, 0 deletions
diff --git a/edify/expr.c b/edify/expr.c
index 72e5100..df3c1ab 100644
--- a/edify/expr.c
+++ b/edify/expr.c
@@ -67,6 +67,7 @@ char* ConcatFn(const char* name, State* state, int argc, Expr* argv[]) {
for (i = 0; i < argc; ++i) {
free(strings[i]);
}
+ free(strings);
return result;
}
@@ -389,11 +390,13 @@ int ReadArgs(State* state, Expr* argv[], int count, ...) {
for (j = 0; j < i; ++j) {
free(args[j]);
}
+ free(args);
return -1;
}
*(va_arg(v, char**)) = args[i];
}
va_end(v);
+ free(args);
return 0;
}
diff --git a/edify/main.c b/edify/main.c
index 0e36108..a2b74ad 100644
--- a/edify/main.c
+++ b/edify/main.c
@@ -181,6 +181,10 @@ int main(int argc, char** argv) {
}
FILE* f = fopen(argv[1], "r");
+ if (f == NULL) {
+ printf("%s: %s: No such file or directory\n", argv[0], argv[1]);
+ return 1;
+ }
char buffer[8192];
int size = fread(buffer, 1, 8191, f);
fclose(f);