From cc9932b2919d5ca5aa7a38dc9776306e8bbca820 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 20 Apr 2022 17:11:42 +0900 Subject: [PATCH] Fix: null name is added when using android_set_process_profiles This CL fixes a bug that null names are passed when profiles are set via android_set_process_profiles. This is because the `profiles_` vector was initialized with the number of task profiles and then we append the actual task profile names to the vector. As a result, when {"a", "b"} was given, the vector ended up having {"", "", "a", "b"}. Fixing this by correctly using reserve(). Bug: N/A Test: m Change-Id: I28d6c2e891b01a2d3a8a88d9d0652fe0dbffac96 --- libprocessgroup/processgroup.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index edda41428..e3a80e97b 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -166,7 +166,8 @@ bool SetTaskProfiles(int tid, const std::vector& profiles, bool use // https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3574427/5/src/linux/android.rs#12 extern "C" bool android_set_process_profiles(uid_t uid, pid_t pid, size_t num_profiles, const char* profiles[]) { - std::vector profiles_(num_profiles); + std::vector profiles_; + profiles_.reserve(num_profiles); for (size_t i = 0; i < num_profiles; i++) { profiles_.emplace_back(profiles[i]); }