Fix several memleak problems found by covscan
Some memleak issues is found by static analysis tools, and can confirm irqbalance is leaking memory slowly when there are incomming connection to socket. This patch could solve the memleak problem.
This commit is contained in:
parent
808c7198ac
commit
85d37098a5
16
irqbalance.c
16
irqbalance.c
|
@ -372,11 +372,11 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||||
sock = accept(fd, NULL, NULL);
|
sock = accept(fd, NULL, NULL);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
log(TO_ALL, LOG_WARNING, "Connection couldn't be accepted.\n");
|
log(TO_ALL, LOG_WARNING, "Connection couldn't be accepted.\n");
|
||||||
return TRUE;
|
goto out;
|
||||||
}
|
}
|
||||||
if ((recv_size = recvmsg(sock, &msg, 0)) < 0) {
|
if ((recv_size = recvmsg(sock, &msg, 0)) < 0) {
|
||||||
log(TO_ALL, LOG_WARNING, "Error while receiving data.\n");
|
log(TO_ALL, LOG_WARNING, "Error while receiving data.\n");
|
||||||
return TRUE;
|
goto out;
|
||||||
}
|
}
|
||||||
cmsg = CMSG_FIRSTHDR(&msg);
|
cmsg = CMSG_FIRSTHDR(&msg);
|
||||||
if ((cmsg->cmsg_level == SOL_SOCKET) &&
|
if ((cmsg->cmsg_level == SOL_SOCKET) &&
|
||||||
|
@ -388,7 +388,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||||
}
|
}
|
||||||
if (!valid_user) {
|
if (!valid_user) {
|
||||||
log(TO_ALL, LOG_INFO, "Permission denied for user to connect to socket.\n");
|
log(TO_ALL, LOG_INFO, "Permission denied for user to connect to socket.\n");
|
||||||
return TRUE;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strncmp(buff, "stats", strlen("stats"))) {
|
if (!strncmp(buff, "stats", strlen("stats"))) {
|
||||||
|
@ -408,6 +408,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||||
if (new_iterval >= 1) {
|
if (new_iterval >= 1) {
|
||||||
sleep_interval = new_iterval;
|
sleep_interval = new_iterval;
|
||||||
}
|
}
|
||||||
|
free(sleep_string);
|
||||||
} else if (!(strncmp(buff + strlen("settings "), "ban irqs ",
|
} else if (!(strncmp(buff + strlen("settings "), "ban irqs ",
|
||||||
strlen("ban irqs ")))) {
|
strlen("ban irqs ")))) {
|
||||||
char *end;
|
char *end;
|
||||||
|
@ -419,12 +420,14 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||||
cl_banned_irqs = NULL;
|
cl_banned_irqs = NULL;
|
||||||
need_rescan = 1;
|
need_rescan = 1;
|
||||||
if (!strncmp(irq_string, "NONE", strlen("NONE"))) {
|
if (!strncmp(irq_string, "NONE", strlen("NONE"))) {
|
||||||
return TRUE;
|
free(irq_string);
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
int irq = strtoul(irq_string, &end, 10);
|
int irq = strtoul(irq_string, &end, 10);
|
||||||
do {
|
do {
|
||||||
add_cl_banned_irq(irq);
|
add_cl_banned_irq(irq);
|
||||||
} while((irq = strtoul(end, &end, 10)));
|
} while((irq = strtoul(end, &end, 10)));
|
||||||
|
free(irq_string);
|
||||||
} else if (!(strncmp(buff + strlen("settings "), "cpus ",
|
} else if (!(strncmp(buff + strlen("settings "), "cpus ",
|
||||||
strlen("cpus")))) {
|
strlen("cpus")))) {
|
||||||
char *cpu_ban_string = malloc(
|
char *cpu_ban_string = malloc(
|
||||||
|
@ -436,6 +439,7 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||||
banned_cpumask_from_ui = NULL;
|
banned_cpumask_from_ui = NULL;
|
||||||
}
|
}
|
||||||
need_rescan = 1;
|
need_rescan = 1;
|
||||||
|
free(cpu_ban_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!strncmp(buff, "setup", strlen("setup"))) {
|
if (!strncmp(buff, "setup", strlen("setup"))) {
|
||||||
|
@ -450,10 +454,14 @@ gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attri
|
||||||
snprintf(setup + strlen(setup), strlen(banned) + 7 + 1,
|
snprintf(setup + strlen(setup), strlen(banned) + 7 + 1,
|
||||||
"BANNED %s", banned);
|
"BANNED %s", banned);
|
||||||
send(sock, setup, strlen(setup), 0);
|
send(sock, setup, strlen(setup), 0);
|
||||||
|
free(setup);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(sock);
|
close(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(msg.msg_control);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ struct msghdr * create_credentials_msg()
|
||||||
cmsg->cmsg_len = CMSG_LEN(sizeof(struct ucred));
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct ucred));
|
||||||
memcpy(CMSG_DATA(cmsg), credentials, sizeof(struct ucred));
|
memcpy(CMSG_DATA(cmsg), credentials, sizeof(struct ucred));
|
||||||
|
|
||||||
|
free(credentials);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +88,8 @@ void send_settings(char *data)
|
||||||
sendmsg(socket_fd, msg, 0);
|
sendmsg(socket_fd, msg, 0);
|
||||||
|
|
||||||
close(socket_fd);
|
close(socket_fd);
|
||||||
|
free(msg->msg_control);
|
||||||
|
free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
char * get_data(char *string)
|
char * get_data(char *string)
|
||||||
|
@ -115,6 +118,8 @@ char * get_data(char *string)
|
||||||
int len = recv(socket_fd, data, 8192, 0);
|
int len = recv(socket_fd, data, 8192, 0);
|
||||||
close(socket_fd);
|
close(socket_fd);
|
||||||
data[len] = '\0';
|
data[len] = '\0';
|
||||||
|
free(msg->msg_control);
|
||||||
|
free(msg);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +128,7 @@ void parse_setup(char *setup_data)
|
||||||
char *token, *ptr;
|
char *token, *ptr;
|
||||||
int i,j;
|
int i,j;
|
||||||
char *copy;
|
char *copy;
|
||||||
|
irq_t *new_irq = NULL;
|
||||||
if((setup_data == NULL) || (strlen(setup_data) == 0)) return;
|
if((setup_data == NULL) || (strlen(setup_data) == 0)) return;
|
||||||
copy = strdup(setup_data);
|
copy = strdup(setup_data);
|
||||||
if (!copy)
|
if (!copy)
|
||||||
|
@ -136,7 +142,7 @@ void parse_setup(char *setup_data)
|
||||||
token = strtok_r(NULL, " ", &ptr);
|
token = strtok_r(NULL, " ", &ptr);
|
||||||
/* Parse banned IRQ data */
|
/* Parse banned IRQ data */
|
||||||
while(!strncmp(token, "IRQ", strlen("IRQ"))) {
|
while(!strncmp(token, "IRQ", strlen("IRQ"))) {
|
||||||
irq_t *new_irq = malloc(sizeof(irq_t));
|
new_irq = malloc(sizeof(irq_t));
|
||||||
new_irq->vector = strtol(strtok_r(NULL, " ", &ptr), NULL, 10);
|
new_irq->vector = strtol(strtok_r(NULL, " ", &ptr), NULL, 10);
|
||||||
token = strtok_r(NULL, " ", &ptr);
|
token = strtok_r(NULL, " ", &ptr);
|
||||||
if(strncmp(token, "LOAD", strlen("LOAD"))) goto out;
|
if(strncmp(token, "LOAD", strlen("LOAD"))) goto out;
|
||||||
|
@ -151,6 +157,7 @@ void parse_setup(char *setup_data)
|
||||||
new_irq->assigned_to = NULL;
|
new_irq->assigned_to = NULL;
|
||||||
setup.banned_irqs = g_list_append(setup.banned_irqs, new_irq);
|
setup.banned_irqs = g_list_append(setup.banned_irqs, new_irq);
|
||||||
token = strtok_r(NULL, " ", &ptr);
|
token = strtok_r(NULL, " ", &ptr);
|
||||||
|
new_irq = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strncmp(token, "BANNED", strlen("BANNED"))) goto out;
|
if(strncmp(token, "BANNED", strlen("BANNED"))) goto out;
|
||||||
|
@ -165,6 +172,7 @@ void parse_setup(char *setup_data)
|
||||||
banned_cpu);
|
banned_cpu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(map);
|
||||||
|
|
||||||
}
|
}
|
||||||
free(copy);
|
free(copy);
|
||||||
|
@ -173,6 +181,9 @@ void parse_setup(char *setup_data)
|
||||||
out: {
|
out: {
|
||||||
/* Invalid data presented */
|
/* Invalid data presented */
|
||||||
printf("Invalid data sent. Unexpected token: %s", token);
|
printf("Invalid data sent. Unexpected token: %s", token);
|
||||||
|
if (new_irq) {
|
||||||
|
free(new_irq);
|
||||||
|
}
|
||||||
free(copy);
|
free(copy);
|
||||||
g_list_free(tree);
|
g_list_free(tree);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -240,6 +251,8 @@ void parse_into_tree(char *data)
|
||||||
cpu_node_t *parent = NULL;
|
cpu_node_t *parent = NULL;
|
||||||
char *copy;
|
char *copy;
|
||||||
tree = NULL;
|
tree = NULL;
|
||||||
|
irq_t *new_irq = NULL;
|
||||||
|
cpu_node_t *new = NULL;
|
||||||
|
|
||||||
if (!data || strlen(data) == 0)
|
if (!data || strlen(data) == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -255,7 +268,7 @@ void parse_into_tree(char *data)
|
||||||
free(copy);
|
free(copy);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
cpu_node_t *new = malloc(sizeof(cpu_node_t));
|
new = malloc(sizeof(cpu_node_t));
|
||||||
new->irqs = NULL;
|
new->irqs = NULL;
|
||||||
new->children = NULL;
|
new->children = NULL;
|
||||||
new->cpu_list = NULL;
|
new->cpu_list = NULL;
|
||||||
|
@ -279,7 +292,7 @@ void parse_into_tree(char *data)
|
||||||
|
|
||||||
/* Parse assigned IRQ data */
|
/* Parse assigned IRQ data */
|
||||||
while((token != NULL) && (!strncmp(token, "IRQ", strlen("IRQ")))) {
|
while((token != NULL) && (!strncmp(token, "IRQ", strlen("IRQ")))) {
|
||||||
irq_t *new_irq = malloc(sizeof(irq_t));
|
new_irq = malloc(sizeof(irq_t));
|
||||||
new_irq->vector = strtol(strtok_r(NULL, " ", &ptr), NULL, 10);
|
new_irq->vector = strtol(strtok_r(NULL, " ", &ptr), NULL, 10);
|
||||||
token = strtok_r(NULL, " ", &ptr);
|
token = strtok_r(NULL, " ", &ptr);
|
||||||
if(strncmp(token, "LOAD", strlen("LOAD"))) goto out;
|
if(strncmp(token, "LOAD", strlen("LOAD"))) goto out;
|
||||||
|
@ -293,6 +306,7 @@ void parse_into_tree(char *data)
|
||||||
new_irq->is_banned = 0;
|
new_irq->is_banned = 0;
|
||||||
new->irqs = g_list_append(new->irqs, new_irq);
|
new->irqs = g_list_append(new->irqs, new_irq);
|
||||||
token = strtok_r(NULL, " ", &ptr);
|
token = strtok_r(NULL, " ", &ptr);
|
||||||
|
new_irq = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((token == NULL) || (strncmp(token, "IRQ", strlen("IRQ")))) {
|
if((token == NULL) || (strncmp(token, "IRQ", strlen("IRQ")))) {
|
||||||
|
@ -306,6 +320,8 @@ void parse_into_tree(char *data)
|
||||||
parent = new;
|
parent = new;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new = NULL;
|
||||||
}
|
}
|
||||||
free(copy);
|
free(copy);
|
||||||
for_each_node(tree, assign_cpu_lists, NULL);
|
for_each_node(tree, assign_cpu_lists, NULL);
|
||||||
|
@ -315,6 +331,12 @@ void parse_into_tree(char *data)
|
||||||
out: {
|
out: {
|
||||||
/* Invalid data presented */
|
/* Invalid data presented */
|
||||||
printf("Invalid data sent. Unexpected token: %s\n", token);
|
printf("Invalid data sent. Unexpected token: %s\n", token);
|
||||||
|
if (new_irq) {
|
||||||
|
free(new_irq);
|
||||||
|
}
|
||||||
|
if (new) {
|
||||||
|
free(new);
|
||||||
|
}
|
||||||
g_list_free(tree);
|
g_list_free(tree);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -330,6 +352,7 @@ gboolean rescan_tree(gpointer data __attribute__((unused)))
|
||||||
display_tree();
|
display_tree();
|
||||||
}
|
}
|
||||||
free(setup_data);
|
free(setup_data);
|
||||||
|
free(irqbalance_data);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
ui/ui.c
2
ui/ui.c
|
@ -71,6 +71,7 @@ char * check_control_in_sleep_input(int max_len, int column_offest, int line_off
|
||||||
attrset(COLOR_PAIR(6));
|
attrset(COLOR_PAIR(6));
|
||||||
break;
|
break;
|
||||||
case 27:
|
case 27:
|
||||||
|
free(input_to);
|
||||||
return NULL;
|
return NULL;
|
||||||
default:
|
default:
|
||||||
input_to[iteration] = new;
|
input_to[iteration] = new;
|
||||||
|
@ -115,6 +116,7 @@ int get_valid_sleep_input(int column_offest)
|
||||||
input);
|
input);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
free(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
attrset(COLOR_PAIR(1));
|
attrset(COLOR_PAIR(1));
|
||||||
|
|
Loading…
Reference in a new issue