Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/common/bridge/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ envoy_error_code_t errorCodeFromLocalStatus(Http::Code status);
template <class T> envoy_map makeEnvoyMap(const T& map) {
envoy_map new_map;
new_map.length = std::size(map);
new_map.entries = new envoy_map_entry[std::size(map)];
new_map.entries =
static_cast<envoy_map_entry*>(safe_malloc(sizeof(envoy_map_entry) * std::size(map)));

uint64_t i = 0;
for (const auto& e : map) {
Expand Down
12 changes: 8 additions & 4 deletions test/common/http/header_utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ envoy_data envoyTestString(std::string& s, uint32_t* sentinel) {
}

TEST(RequestHeaderDataConstructorTest, FromCToCppEmpty) {
envoy_map_entry* header_array = new envoy_map_entry[0];
envoy_map_entry* header_array =
static_cast<envoy_map_entry*>(safe_malloc(sizeof(envoy_map_entry) * 0));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use makeEnvoyMap here? Would be nice to keep the init logic in one place

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! I was able to do this for both this test and the subsequent one. The rest of the tests, though, seem more elaborate. They set up envoy_map instances in which the envoy_data is wired up to use envoy_test_release() when releasing the data to do tracking. makeEnvoyMap seems to use copyToBridgeData() to populate the map which I think makes this a non-starter. But I'm not entirely familiar with this code so maybe there's a cleaner approach?

envoy_headers empty_headers = {0, header_array};

RequestHeaderMapPtr cpp_headers = Utility::toRequestHeaders(empty_headers);
Expand All @@ -27,7 +28,8 @@ TEST(RequestHeaderDataConstructorTest, FromCToCppEmpty) {
}

TEST(RequestTrailerDataConstructorTest, FromCToCppEmpty) {
envoy_map_entry* header_array = new envoy_map_entry[0];
envoy_map_entry* header_array =
static_cast<envoy_map_entry*>(safe_malloc(sizeof(envoy_map_entry) * 0));
envoy_headers empty_trailers = {0, header_array};

RequestTrailerMapPtr cpp_trailers = Utility::toRequestTrailers(empty_trailers);
Expand All @@ -40,7 +42,8 @@ TEST(RequestHeaderDataConstructorTest, FromCToCpp) {
std::vector<std::pair<std::string, std::string>> headers = {
{":method", "GET"}, {":scheme", "https"}, {":authority", "api.lyft.com"}, {":path", "/ping"}};

envoy_map_entry* header_array = new envoy_map_entry[headers.size()];
envoy_map_entry* header_array =
static_cast<envoy_map_entry*>(safe_malloc(sizeof(envoy_map_entry) * headers.size()));

uint32_t* sentinel = new uint32_t;
*sentinel = 0;
Expand Down Expand Up @@ -81,7 +84,8 @@ TEST(RequestTrailerDataConstructorTest, FromCToCpp) {
std::vector<std::pair<std::string, std::string>> trailers = {
{"processing-duration-ms", "25"}, {"response-compression-ratio", "0.61"}};

envoy_map_entry* header_array = new envoy_map_entry[trailers.size()];
envoy_map_entry* header_array =
static_cast<envoy_map_entry*>(safe_malloc(sizeof(envoy_map_entry) * trailers.size()));

uint32_t* sentinel = new uint32_t;
*sentinel = 0;
Expand Down