Skip to content
Permalink
Browse files

Removed a few memory leaks when a connection could not be established…

…. Fixed a possible dereference of a NULL pointer in ros_login.
  • Loading branch information
haakonnessjoen committed May 7, 2014
1 parent 2dc3674 commit 7bc5ee8d24390312898be14cbae9f055dc2065d3
Showing with 14 additions and 7 deletions.
  1. +14 −7 librouteros.c
@@ -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;
@@ -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;
}

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

@@ -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;
}

0 comments on commit 7bc5ee8

Please sign in to comment.
You can’t perform that action at this time.