vnc-auth-sasl: fix a memory leak

Fix a memory leak reported by cppcheck:
[/src/qemu/ui/vnc-auth-sasl.c:448]: (error) Memory leak: mechname

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
Blue Swirl 2011-01-12 19:48:56 +00:00
parent 00e076795f
commit 8ce7d35273

View File

@ -444,22 +444,19 @@ static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_
if (vs->sasl.mechlist[len] != '\0' && if (vs->sasl.mechlist[len] != '\0' &&
vs->sasl.mechlist[len] != ',') { vs->sasl.mechlist[len] != ',') {
VNC_DEBUG("One %d", vs->sasl.mechlist[len]); VNC_DEBUG("One %d", vs->sasl.mechlist[len]);
vnc_client_error(vs); goto fail;
return -1;
} }
} else { } else {
char *offset = strstr(vs->sasl.mechlist, mechname); char *offset = strstr(vs->sasl.mechlist, mechname);
VNC_DEBUG("Two %p\n", offset); VNC_DEBUG("Two %p\n", offset);
if (!offset) { if (!offset) {
vnc_client_error(vs); goto fail;
return -1;
} }
VNC_DEBUG("Two '%s'\n", offset); VNC_DEBUG("Two '%s'\n", offset);
if (offset[-1] != ',' || if (offset[-1] != ',' ||
(offset[len] != '\0'&& (offset[len] != '\0'&&
offset[len] != ',')) { offset[len] != ',')) {
vnc_client_error(vs); goto fail;
return -1;
} }
} }
@ -469,6 +466,11 @@ static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_
VNC_DEBUG("Validated mechname '%s'\n", mechname); VNC_DEBUG("Validated mechname '%s'\n", mechname);
vnc_read_when(vs, protocol_client_auth_sasl_start_len, 4); vnc_read_when(vs, protocol_client_auth_sasl_start_len, 4);
return 0; return 0;
fail:
vnc_client_error(vs);
free(mechname);
return -1;
} }
static int protocol_client_auth_sasl_mechname_len(VncState *vs, uint8_t *data, size_t len) static int protocol_client_auth_sasl_mechname_len(VncState *vs, uint8_t *data, size_t len)