Skip to content

Commit d62002e

Browse files
szsambk138
authored andcommitted
examples: check return values of malloc for null
1 parent b038c7d commit d62002e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

examples/client/SDLvncviewer.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,21 @@ static void got_selection_utf8(rfbClient *cl, const char *buf, int len)
437437

438438

439439
static rfbCredential* get_credential(rfbClient* cl, int credentialType){
440-
rfbCredential *c = malloc(sizeof(rfbCredential));
440+
rfbCredential *c = malloc(sizeof(rfbCredential));
441+
if (!c) {
442+
return NULL;
443+
}
441444
c->userCredential.username = malloc(RFB_BUF_SIZE);
445+
if (!c->userCredential.username) {
446+
free(c);
447+
return NULL;
448+
}
442449
c->userCredential.password = malloc(RFB_BUF_SIZE);
450+
if (!c->userCredential.password) {
451+
free(c->userCredential.username);
452+
free(c);
453+
return NULL;
454+
}
443455

444456
if(credentialType != rfbCredentialTypeUser) {
445457
rfbClientErr("something else than username and password required for authentication\n");

0 commit comments

Comments
 (0)