Skip to content

Commit

Permalink
Fix dereference before null check.
Browse files Browse the repository at this point in the history
Coverity Scan 1405815.
  • Loading branch information
ralight committed Jan 23, 2020
1 parent db62f98 commit 18f0508
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ int main(int argc, char *argv[])
#endif
}
}
if(listensock == NULL){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to start any listening sockets, exiting.");
return 1;
}

rc = drop_privileges(&config, false);
if(rc != MOSQ_ERR_SUCCESS) return rc;
Expand Down Expand Up @@ -416,18 +420,16 @@ int main(int argc, char *argv[])

db__close(&int_db);

if(listensock){
for(i=0; i<listensock_count; i++){
if(listensock[i] != INVALID_SOCKET){
for(i=0; i<listensock_count; i++){
if(listensock[i] != INVALID_SOCKET){
#ifndef WIN32
close(listensock[i]);
close(listensock[i]);
#else
closesocket(listensock[i]);
closesocket(listensock[i]);
#endif
}
}
mosquitto__free(listensock);
}
mosquitto__free(listensock);

mosquitto_security_module_cleanup(&int_db);

Expand Down

0 comments on commit 18f0508

Please sign in to comment.