pmc: Fix stack std::string lifetime

It's invalid to reference a C++ string's c_str() buffer after the object
goes out of scope.  Adjust the scope of the string to match the use in
write(2) to fix the misuse.

CID:		1393383
Reported by:	Coverity
This commit is contained in:
Conrad Meyer 2019-05-22 01:22:33 +00:00
parent 8bbd9a3839
commit 11a5c93d51
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=348078

View file

@ -180,11 +180,12 @@ pmc_find_name(idmap & map, uint32_t id, char *list[LIST_MAX], int count)
static void
pmc_log_event(int fd, struct pmclog_ev *ev, bool json)
{
string ret;
int len;
const void *buf;
if (json) {
string ret = event_to_json(ev);
ret = event_to_json(ev);
buf = ret.c_str();
len = ret.size();
} else {