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-02-12 03:10:31 +0100
commitd6c93afcc28cc65217ba65eeb646009c4f15a2ad (patch)
tree7de6bb409c2d741e9bb3922ab79e446090baacdd /updater/install.cpp
parentMerge "IO fault injection for OTA packages" (diff)
downloadandroid_bootable_recovery-d6c93afcc28cc65217ba65eeb646009c4f15a2ad.tar
android_bootable_recovery-d6c93afcc28cc65217ba65eeb646009c4f15a2ad.tar.gz
android_bootable_recovery-d6c93afcc28cc65217ba65eeb646009c4f15a2ad.tar.bz2
android_bootable_recovery-d6c93afcc28cc65217ba65eeb646009c4f15a2ad.tar.lz
android_bootable_recovery-d6c93afcc28cc65217ba65eeb646009c4f15a2ad.tar.xz
android_bootable_recovery-d6c93afcc28cc65217ba65eeb646009c4f15a2ad.tar.zst
android_bootable_recovery-d6c93afcc28cc65217ba65eeb646009c4f15a2ad.zip
Diffstat (limited to 'updater/install.cpp')
-rw-r--r--updater/install.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/updater/install.cpp b/updater/install.cpp
index 1cd9a5690..413e147a1 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;
}