Skip to content

Commit

Permalink
Removed a few memory leaks when a connection could not be established…
Browse files Browse the repository at this point in the history
…. Fixed a possible dereference of a NULL pointer in ros_login.
  • Loading branch information
haakonnessjoen committed May 7, 2014
1 parent 2dc3674 commit 7bc5ee8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions librouteros.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,11 @@ struct ros_connection *ros_connect(char *address, int port) {

#ifdef _WIN32
if ((retval = WSAStartup(0x202, &wsaData)) != 0) {
fprintf(stderr,"Server: WSAStartup() failed with error %d\n", retval);
WSACleanup();
return NULL;
}
fprintf(stderr,"Server: WSAStartup() failed with error %d\n", retval);
WSACleanup();
free(conn);
return NULL;
}
#endif

conn->expected_length = 0;
Expand All @@ -341,6 +342,7 @@ struct ros_connection *ros_connect(char *address, int port) {

conn->socket = socket(AF_INET, SOCK_STREAM, 0);
if (conn->socket <= 0) {
free(conn);
return NULL;
}

Expand All @@ -356,6 +358,7 @@ struct ros_connection *ros_connect(char *address, int port) {
-1
#endif
) {
free(conn);
return NULL;
}

Expand Down Expand Up @@ -809,9 +812,13 @@ int ros_login(struct ros_connection *conn, char *username, char *password) {

free(userWord);

// !done == successful login
result = res->done;
ros_result_free(res);
// '!done' flag == successful login
if (res != NULL) {
result = res->done;
ros_result_free(res);
} else {
result = 0;
}

return result;
}
Expand Down

0 comments on commit 7bc5ee8

Please sign in to comment.