Skip to content

Commit 0958967

Browse files
RokerHROLars H. Rohwedder
andauthored
libvncclient,libvncserver: remove unnecessary NULL checks before free()
Co-authored-by: Lars H. Rohwedder <[email protected]>
1 parent 1c5d989 commit 0958967

File tree

11 files changed

+48
-61
lines changed

11 files changed

+48
-61
lines changed

src/libvncclient/cursor.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int h
6060
return FALSE;
6161

6262
/* Allocate memory for pixel data and temporary mask data. */
63-
if(client->rcSource)
64-
free(client->rcSource);
63+
free(client->rcSource);
6564

6665
client->rcSource = malloc((size_t)width * height * bytesPerPixel);
6766
if (client->rcSource == NULL)
@@ -146,8 +145,7 @@ rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int h
146145
return FALSE;
147146
}
148147

149-
if(client->rcMask)
150-
free(client->rcMask);
148+
free(client->rcMask);
151149

152150
client->rcMask = malloc((size_t)width * height);
153151
if (client->rcMask == NULL) {

src/libvncclient/rfbclient.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ HandleVncAuth(rfbClient *client)
605605
static void
606606
FreeUserCredential(rfbCredential *cred)
607607
{
608-
if (cred->userCredential.username) free(cred->userCredential.username);
609-
if (cred->userCredential.password) free(cred->userCredential.password);
608+
free(cred->userCredential.username);
609+
free(cred->userCredential.password);
610610
free(cred);
611611
}
612612

src/libvncclient/tls_openssl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,10 @@ HandleAnonTLSAuth(rfbClient* client)
527527
static void
528528
FreeX509Credential(rfbCredential *cred)
529529
{
530-
if (cred->x509Credential.x509CACertFile) free(cred->x509Credential.x509CACertFile);
531-
if (cred->x509Credential.x509CACrlFile) free(cred->x509Credential.x509CACrlFile);
532-
if (cred->x509Credential.x509ClientCertFile) free(cred->x509Credential.x509ClientCertFile);
533-
if (cred->x509Credential.x509ClientKeyFile) free(cred->x509Credential.x509ClientKeyFile);
530+
free(cred->x509Credential.x509CACertFile);
531+
free(cred->x509Credential.x509CACrlFile);
532+
free(cred->x509Credential.x509ClientCertFile);
533+
free(cred->x509Credential.x509ClientKeyFile);
534534
free(cred);
535535
}
536536

src/libvncclient/vncviewer.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,8 @@ rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv) {
466466
} else if (i+1<*argc && strcmp(argv[i], "-repeaterdest") == 0) {
467467
char* colon=strchr(argv[i+1],':');
468468

469-
if(client->destHost)
470-
free(client->destHost);
471-
client->destPort = 5900;
469+
free(client->destHost);
470+
client->destPort = 5900;
472471

473472
client->destHost = strdup(argv[i+1]);
474473
if(client->destHost && colon) {
@@ -479,8 +478,7 @@ rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv) {
479478
} else {
480479
char* colon=strrchr(argv[i],':');
481480

482-
if(client->serverHost)
483-
free(client->serverHost);
481+
free(client->serverHost);
484482

485483
if(colon) {
486484
client->serverHost = strdup(argv[i]);
@@ -537,11 +535,8 @@ void rfbClientCleanup(rfbClient* client) {
537535
#endif /* LIBVNCSERVER_HAVE_LIBJPEG */
538536
#endif
539537

540-
if (client->ultra_buffer)
541-
free(client->ultra_buffer);
542-
543-
if (client->raw_buffer)
544-
free(client->raw_buffer);
538+
free(client->ultra_buffer);
539+
free(client->raw_buffer);
545540

546541
FreeTLS(client);
547542

@@ -551,8 +546,7 @@ void rfbClientCleanup(rfbClient* client) {
551546
client->clientData = next;
552547
}
553548

554-
if(client->vncRec)
555-
free(client->vncRec);
549+
free(client->vncRec);
556550

557551
if (client->sock != RFB_INVALID_SOCKET)
558552
rfbCloseSocket(client->sock);
@@ -562,18 +556,13 @@ void rfbClientCleanup(rfbClient* client) {
562556
rfbCloseSocket(client->listen6Sock);
563557
free(client->desktopName);
564558
free(client->serverHost);
565-
if (client->destHost)
566-
free(client->destHost);
567-
if (client->clientAuthSchemes)
568-
free(client->clientAuthSchemes);
569-
if(client->rcSource)
570-
free(client->rcSource);
571-
if(client->rcMask)
572-
free(client->rcMask);
559+
free(client->destHost);
560+
free(client->clientAuthSchemes);
561+
free(client->rcSource);
562+
free(client->rcMask);
573563

574564
#ifdef LIBVNCSERVER_HAVE_SASL
575-
if (client->saslSecret)
576-
free(client->saslSecret);
565+
free(client->saslSecret);
577566
if (client->saslconn)
578567
sasl_dispose(&client->saslconn);
579568
#endif /* LIBVNCSERVER_HAVE_SASL */

src/libvncserver/cursor.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ rfbCursorPtr rfbMakeXCursor(int width,int height,char* cursorString,char* maskSt
291291
cursor->mask = (unsigned char*)rfbMakeMaskForXCursor(width,height,(char*)cursor->source);
292292
cursor->cleanupMask = TRUE;
293293

294-
return(cursor);
294+
return cursor;
295295
}
296296

297297
char* rfbMakeMaskForXCursor(int width,int height,char* source)
@@ -367,16 +367,17 @@ char* rfbMakeMaskFromAlphaSource(int width,int height,unsigned char* alphaSource
367367
void rfbFreeCursor(rfbCursorPtr cursor)
368368
{
369369
if(cursor) {
370-
if(cursor->cleanupRichSource && cursor->richSource)
371-
free(cursor->richSource);
372-
if(cursor->cleanupRichSource && cursor->alphaSource)
373-
free(cursor->alphaSource);
374-
if(cursor->cleanupSource && cursor->source)
375-
free(cursor->source);
376-
if(cursor->cleanupMask && cursor->mask)
377-
free(cursor->mask);
370+
if(cursor->cleanupRichSource)
371+
{
372+
free(cursor->richSource);
373+
free(cursor->alphaSource);
374+
}
375+
if(cursor->cleanupSource)
376+
free(cursor->source);
377+
if(cursor->cleanupMask)
378+
free(cursor->mask);
378379
if(cursor->cleanup)
379-
free(cursor);
380+
free(cursor);
380381
else {
381382
cursor->cleanup=cursor->cleanupSource=cursor->cleanupMask
382383
=cursor->cleanupRichSource=FALSE;
@@ -398,7 +399,7 @@ void rfbMakeXCursorFromRichCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor
398399
unsigned char bit;
399400
int interp = 0;
400401

401-
if(cursor->source && cursor->cleanupSource)
402+
if(cursor->cleanupSource)
402403
free(cursor->source);
403404
cursor->source=(unsigned char*)calloc(w,cursor->height);
404405
if(!cursor->source)
@@ -475,7 +476,7 @@ void rfbMakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor
475476
unsigned char *cp;
476477
unsigned char bit;
477478

478-
if(cursor->richSource && cursor->cleanupRichSource)
479+
if(cursor->cleanupRichSource)
479480
free(cursor->richSource);
480481
cp=cursor->richSource=(unsigned char*)calloc((size_t)cursor->width*bpp,cursor->height);
481482
if(!cp)

src/libvncserver/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,9 +1163,9 @@ void rfbScreenCleanup(rfbScreenInfoPtr screen)
11631163
}
11641164
rfbReleaseClientIterator(i);
11651165

1166-
#define FREE_IF(x) if(screen->x) free(screen->x)
1167-
FREE_IF(colourMap.data.bytes);
1168-
FREE_IF(underCursorBuffer);
1166+
#define FREE_SCREEN_MEMBER(member) free(screen->member)
1167+
FREE_SCREEN_MEMBER(colourMap.data.bytes);
1168+
FREE_SCREEN_MEMBER(underCursorBuffer);
11691169
TINI_MUTEX(screen->cursorMutex);
11701170

11711171
if(screen->cursor != &myCursor)

src/libvncserver/rfbserver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ rfbClientConnectionGone(rfbClientPtr cl)
636636
sraRgnDestroy(cl->requestedRegion);
637637
sraRgnDestroy(cl->copyRegion);
638638

639-
if (cl->translateLookupTable) free(cl->translateLookupTable);
639+
free(cl->translateLookupTable);
640640

641641
TINI_COND(cl->updateCond);
642642
TINI_MUTEX(cl->updateMutex);
@@ -1115,7 +1115,7 @@ rfbSetServerVersionIdentity(rfbScreenInfoPtr screen, char *fmt, ...)
11151115
vsnprintf(buffer, sizeof(buffer)-1, fmt, ap);
11161116
va_end(ap);
11171117

1118-
if (screen->versionString!=NULL) free(screen->versionString);
1118+
free(screen->versionString);
11191119
screen->versionString = strdup(buffer);
11201120
}
11211121

src/libvncserver/zrleoutstream.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ static rfbBool zrleBufferAlloc(zrleBuffer *buffer, int size)
4040

4141
static void zrleBufferFree(zrleBuffer *buffer)
4242
{
43-
if (buffer->start)
44-
free(buffer->start);
43+
free(buffer->start);
4544
buffer->start = buffer->ptr = buffer->end = NULL;
4645
}
4746

test/bmp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ int loadppm(int *fd, unsigned char **buf, int *w, int *h,
168168

169169
finally:
170170
if(fs) {fclose(fs); *fd=-1;}
171-
if(tempbuf) free(tempbuf);
171+
free(tempbuf);
172172
return retcode;
173173
}
174174

@@ -262,7 +262,7 @@ int loadbmp(char *filename, unsigned char **buf, int *w, int *h,
262262
srcbottomup!=dstbottomup);
263263

264264
finally:
265-
if(tempbuf) free(tempbuf);
265+
free(tempbuf);
266266
if(fd!=-1) close(fd);
267267
return retcode;
268268
}
@@ -291,7 +291,7 @@ int saveppm(char *filename, unsigned char *buf, int w, int h,
291291
if((fwrite(tempbuf, w*h*3, 1, fs))!=1) _throw("Write error");
292292

293293
finally:
294-
if(tempbuf) free(tempbuf);
294+
free(tempbuf);
295295
if(fs) fclose(fs);
296296
return retcode;
297297
}
@@ -379,7 +379,7 @@ int savebmp(char *filename, unsigned char *buf, int w, int h,
379379
_throw(strerror(errno));
380380

381381
finally:
382-
if(tempbuf) free(tempbuf);
382+
free(tempbuf);
383383
if(fd!=-1) close(fd);
384384
return retcode;
385385
}

test/tjbench.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,6 @@ int main(int argc, char *argv[])
658658
printf("\n");
659659

660660
bailout:
661-
if(srcbuf) free(srcbuf);
661+
free(srcbuf);
662662
return retval;
663663
}

0 commit comments

Comments
 (0)