summaryrefslogtreecommitdiff
path: root/fastboot/fastboot.cpp
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2021-03-22 16:55:39 -0700
committerYifan Hong <elsk@google.com>2021-03-22 19:30:59 -0700
commite9f067b4eb3f1f052621a6dfabc22d2be240848f (patch)
tree2078bee2d2b9898addddbf6cc3851cef5d5ce62d /fastboot/fastboot.cpp
parent12744bd2ad688b6a7b3cf009f490a86eff508282 (diff)
fastboot driver: Fix fd ownership.
load_sparse_files assumes that the client maintains the lifetime of the input fd is longer than the output sparse_file handle. Bug: 183409401 Bug: 183223098 Test: flash super image Change-Id: I295b912c665577b5767a133f3148e58a22733998
Diffstat (limited to 'fastboot/fastboot.cpp')
-rw-r--r--fastboot/fastboot.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index e1bf98468..402c5c5f7 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -911,8 +911,9 @@ static bool load_buf_fd(unique_fd fd, struct fastboot_buffer* buf) {
lseek(fd, 0, SEEK_SET);
int64_t limit = get_sparse_limit(sz);
+ buf->fd = std::move(fd);
if (limit) {
- sparse_file** s = load_sparse_files(fd, limit);
+ sparse_file** s = load_sparse_files(buf->fd.get(), limit);
if (s == nullptr) {
return false;
}
@@ -921,7 +922,6 @@ static bool load_buf_fd(unique_fd fd, struct fastboot_buffer* buf) {
} else {
buf->type = FB_BUFFER_FD;
buf->data = nullptr;
- buf->fd = std::move(fd);
buf->sz = sz;
}