Skip to content

Commit c6e6170

Browse files
committed
Fix two memory issues detected by asan
`name` and `instance_` both refer to objects that go out of scope. Bug: b/511301172
1 parent 9666115 commit c6e6170

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

base/cvd/cuttlefish/common/libs/utils/flag_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ Flag GflagsCompatFlag(const std::string& name, std::vector<bool>& value,
677677
const bool default_value) {
678678
return GflagsCompatFlag(name)
679679
.Getter([&value]() { return fmt::format("{}", fmt::join(value, ",")); })
680-
.Setter([&name, &value,
680+
.Setter([name, &value,
681681
default_value](const FlagMatch& match) -> Result<void> {
682682
if (match.value.empty()) {
683683
value.clear();

base/cvd/cuttlefish/host/commands/assemble_cvd/disk/kernel_ramdisk_repacker.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ InstanceBootImage::InstanceBootImage(
102102
const CuttlefishConfig::InstanceSpecific& instance,
103103
const BootImageFlag& boot_image_flag)
104104
: config_(&config),
105-
instance_(&instance),
105+
instance_(instance),
106106
boot_image_flag_(&boot_image_flag) {
107107
// Repacking a boot.img doesn't work with Gem5 because the user must always
108108
// specify a vmlinux instead of an arm64 Image, and that file can be too
109109
// large to be repacked. Skip repack of boot.img on Gem5, as we need to be
110110
// able to extract the ramdisk.img in a later stage and so this step must
111111
// not fail (..and the repacked kernel wouldn't be used anyway).
112-
if (instance_->kernel_path().empty() || VmManagerIsGem5(*config_)) {
112+
if (instance_.kernel_path().empty() || VmManagerIsGem5(*config_)) {
113113
path_ = boot_image_flag.ForIndex(instance.index());
114114
}
115115
}
@@ -122,13 +122,13 @@ Result<std::string> InstanceBootImage::Generate() {
122122
}
123123

124124
std::string previous_boot_image =
125-
boot_image_flag_->ForIndex(instance_->index());
125+
boot_image_flag_->ForIndex(instance_.index());
126126
CF_EXPECTF(FileHasContent(previous_boot_image), "File not found: {}",
127127
previous_boot_image);
128128

129-
std::string new_path = instance_->PerInstancePath("boot_repacked.img");
129+
std::string new_path = instance_.PerInstancePath("boot_repacked.img");
130130
CF_EXPECT(
131-
RepackBootImage(instance_->kernel_path(), previous_boot_image, new_path),
131+
RepackBootImage(instance_.kernel_path(), previous_boot_image, new_path),
132132
"Failed to regenerate the boot image with the new kernel");
133133
path_ = new_path;
134134

base/cvd/cuttlefish/host/commands/assemble_cvd/disk/kernel_ramdisk_repacker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class InstanceBootImage : public ImageFile {
3838

3939
private:
4040
const CuttlefishConfig* config_;
41-
const CuttlefishConfig::InstanceSpecific* instance_;
41+
const CuttlefishConfig::InstanceSpecific instance_;
4242
const BootImageFlag* boot_image_flag_;
4343
std::optional<std::string> path_;
4444
};

0 commit comments

Comments
 (0)