Skip to content

Commit 6513e95

Browse files
committed
test_http_server: Fix dangling pointer issue
Get(index) returns a copy of a string. That copy is kept alive by the const reference until the end of the GetCStr function. When the GetCStr function returns, the copy is destroyed (and so is its char buffer), so returned pointer to the char buffer becomes dangling. Suggested-by: Krzesimir Nowak <knowak@microsoft.com>
1 parent e4ad96e commit 6513e95

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/update_engine/test_http_server.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,7 @@ class UrlTerms {
466466
return terms[index];
467467
}
468468
inline const char *GetCStr(const off_t index) const {
469-
const string& term = Get(index);
470-
return term.c_str();
469+
return terms[index].c_str();
471470
}
472471
inline int GetInt(const off_t index) const {
473472
return atoi(GetCStr(index));

0 commit comments

Comments
 (0)