interceptor: refactor argv_vector() out of execute_execve

This allows later reuse when adding support for intercepting
posix_spawn().

Bug: 209401200
Signed-off-by: Matthias Maennich <[email protected]>
Change-Id: I035d4e2a2e2539c073a9c8bcf919872137fb2d28
diff --git a/interceptor.cc b/interceptor.cc
index 5e789ff..f0fccf0 100644
--- a/interceptor.cc
+++ b/interceptor.cc
@@ -351,17 +351,22 @@
   }
 }
 
-static int execute_execve(const interceptor::Command& command, char* const envp[]) {
-  std::vector<const char*> c_arguments;
-  c_arguments.reserve(command.arguments().size() + 1);
-  c_arguments[command.arguments().size()] = nullptr;
+static std::vector<const char*> argv_vector(const interceptor::Command& command) {
+  std::vector<const char*> result;
+  result.reserve(command.arguments().size() + 1);
+  result[command.arguments().size()] = nullptr;
   for (const auto& arg : command.arguments()) {
-    c_arguments.push_back(arg.data());
+    result.push_back(arg.c_str());
   }
+  return result;
+}
+
+static int execute_execve(const interceptor::Command& command, char* const envp[]) {
   // TODO: at this point, we could free some memory that is held in Command.
   //       While the arguments vector is reused for arguments, we could free
   //       the EnvMap and the original arguments.
 
   // does not actually return
-  return old_execve(command.program().c_str(), const_cast<char**>(c_arguments.data()), envp);
+  return old_execve(command.program().c_str(), const_cast<char**>(argv_vector(command).data()),
+                    envp);
 }