Don't reference out-of-scope temporary

The string on which we were calling c_str() was a temporary, so the C
string returned would no longer be valid. This issue was detected by a
Coverity scan.

Signed-off-by: Zane Bitter <zbitter@redhat.com>
Reviewed-by: Lon Hohberger <lon@users.sourceforge.net>
This commit is contained in:
Zane Bitter 2011-08-24 18:40:42 +02:00 committed by Lon Hohberger
parent 53a2b293d1
commit b5e1bc6e5f

View File

@ -120,7 +120,7 @@ int
do_lq_request(struct lq_info *info, const char *vm_name,
const char *action)
{
const char *vm_state = NULL;
std::string vm_state;
const char *property = "name";
if (is_uuid(vm_name) == 1) {
property = "uuid";
@ -171,15 +171,15 @@ do_lq_request(struct lq_info *info, const char *vm_name,
goto out;
}
vm_state = domain.getProperty("state").asString().c_str();
vm_state = domain.getProperty("state").asString();
std::cout << vm_name << " " << vm_state << std::endl;
int r;
if (!strcmp( vm_state, "running" ) ||
!strcmp( vm_state, "idle" ) ||
!strcmp( vm_state, "paused" ) ||
!strcmp( vm_state, "no state" ) ) {
if (vm_state == "running" ||
vm_state == "idle" ||
vm_state == "paused" ||
vm_state == "no state") {
r = RESP_OFF;
} else {
r = 0;