summaryrefslogtreecommitdiffstats
path: root/updater/install.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2016-02-11 01:41:10 +0100
committerYabin Cui <yabinc@google.com>2016-03-11 20:11:11 +0100
commit1c522df25f9524eaa0273538b3de0b9ad1b8fcea (patch)
treef2eb88134aca78ed69565d586b54d59c2e1c4f04 /updater/install.cpp
parentrecovery: Remove duplicate variables and functions (diff)
downloadandroid_bootable_recovery-1c522df25f9524eaa0273538b3de0b9ad1b8fcea.tar
android_bootable_recovery-1c522df25f9524eaa0273538b3de0b9ad1b8fcea.tar.gz
android_bootable_recovery-1c522df25f9524eaa0273538b3de0b9ad1b8fcea.tar.bz2
android_bootable_recovery-1c522df25f9524eaa0273538b3de0b9ad1b8fcea.tar.lz
android_bootable_recovery-1c522df25f9524eaa0273538b3de0b9ad1b8fcea.tar.xz
android_bootable_recovery-1c522df25f9524eaa0273538b3de0b9ad1b8fcea.tar.zst
android_bootable_recovery-1c522df25f9524eaa0273538b3de0b9ad1b8fcea.zip
Diffstat (limited to '')
-rw-r--r--updater/install.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/updater/install.cpp b/updater/install.cpp
index a2efc0b97..b7d9e85a2 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -1398,21 +1398,22 @@ Value* ReadFileFn(const char* name, State* state, int argc, Expr* argv[]) {
char* filename;
if (ReadArgs(state, argv, 1, &filename) < 0) return NULL;
- Value* v = reinterpret_cast<Value*>(malloc(sizeof(Value)));
+ Value* v = static_cast<Value*>(malloc(sizeof(Value)));
+ if (v == nullptr) {
+ return nullptr;
+ }
v->type = VAL_BLOB;
+ v->size = -1;
+ v->data = nullptr;
FileContents fc;
if (LoadFileContents(filename, &fc) != 0) {
- free(filename);
- v->size = -1;
- v->data = NULL;
- free(fc.data);
- return v;
+ v->data = static_cast<char*>(malloc(fc.data.size()));
+ if (v->data != nullptr) {
+ memcpy(v->data, fc.data.data(), fc.data.size());
+ v->size = fc.data.size();
+ }
}
-
- v->size = fc.size;
- v->data = (char*)fc.data;
-
free(filename);
return v;
}