fix the memory leak by not using calloc
yay its slightly faster now too thanks to rber and AmyMalik on libera dot chat :3
This commit is contained in:
parent
4de517562f
commit
0893d2dd3a
1 changed files with 3 additions and 5 deletions
8
fbflut.c
8
fbflut.c
|
@ -25,7 +25,7 @@ char *safestrtok(char *str, const char *delim) {
|
||||||
void *handle_connection(void *socket_desc) {
|
void *handle_connection(void *socket_desc) {
|
||||||
int sock = *(int*)socket_desc;
|
int sock = *(int*)socket_desc;
|
||||||
int read_size, read_to;
|
int read_size, read_to;
|
||||||
char *message, *command, client_message[36];
|
char *command, message[36], client_message[36];
|
||||||
|
|
||||||
while ((read_size = recv(sock, client_message, 36, MSG_PEEK)) > 0) {
|
while ((read_size = recv(sock, client_message, 36, MSG_PEEK)) > 0) {
|
||||||
client_message[read_size] = '\0';
|
client_message[read_size] = '\0';
|
||||||
|
@ -43,8 +43,7 @@ void *handle_connection(void *socket_desc) {
|
||||||
|
|
||||||
if (xpos >= 0 && ypos >= 0 && xpos < fb_width && ypos < fb_height) {
|
if (xpos >= 0 && ypos >= 0 && xpos < fb_width && ypos < fb_height) {
|
||||||
if (colorcode[0] == '\0') {
|
if (colorcode[0] == '\0') {
|
||||||
message = calloc(sizeof(char), 36);
|
sprintf(message, "PX %i %i %X\n",xpos,ypos,fbdata[ypos*fb_length+xpos]);
|
||||||
asprintf(&message, "PX %i %i %X\n",xpos,ypos,fbdata[ypos*fb_length+xpos]);
|
|
||||||
write(sock, message, strlen(message));
|
write(sock, message, strlen(message));
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,13 +56,12 @@ void *handle_connection(void *socket_desc) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp("SIZE", command)) {
|
if (!strcmp("SIZE", command)) {
|
||||||
message = calloc(sizeof(char), 36);
|
|
||||||
sprintf(message, "SIZE %i %i\n\0", fb_width, fb_height);
|
sprintf(message, "SIZE %i %i\n\0", fb_width, fb_height);
|
||||||
write(sock, message, strlen(message));
|
write(sock, message, strlen(message));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp("HELP", command)) {
|
if (!strcmp("HELP", command)) {
|
||||||
message = "HELP\nSIZE\nPX x y [color]\n";
|
memcpy(message, "HELP\nSIZE\nPX x y [color]\n", 26);
|
||||||
write(sock, message, strlen(message));
|
write(sock, message, strlen(message));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue