diff options
author | Yabin Cui <yabinc@google.com> | 2016-02-12 19:09:20 +0100 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-02-12 19:09:20 +0100 |
commit | 7f16c7a4c9b457302a0c91c9bd4c739708a9c79e (patch) | |
tree | 1794554fce15ba6e2e8d10a57598ccd0acbe523b /updater/install.cpp | |
parent | Merge "Fix some memory leaks." (diff) | |
parent | applypatch: use vector to store data in FileContents. (diff) | |
download | android_bootable_recovery-7f16c7a4c9b457302a0c91c9bd4c739708a9c79e.tar android_bootable_recovery-7f16c7a4c9b457302a0c91c9bd4c739708a9c79e.tar.gz android_bootable_recovery-7f16c7a4c9b457302a0c91c9bd4c739708a9c79e.tar.bz2 android_bootable_recovery-7f16c7a4c9b457302a0c91c9bd4c739708a9c79e.tar.lz android_bootable_recovery-7f16c7a4c9b457302a0c91c9bd4c739708a9c79e.tar.xz android_bootable_recovery-7f16c7a4c9b457302a0c91c9bd4c739708a9c79e.tar.zst android_bootable_recovery-7f16c7a4c9b457302a0c91c9bd4c739708a9c79e.zip |
Diffstat (limited to 'updater/install.cpp')
-rw-r--r-- | updater/install.cpp | 21 |
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; } |