Commit dfcbc4946cebed46aabe80f7d1643daf21f32d59
1 parent
fc4fd8f6
fix memory problems occured with latest changes
Showing
9 changed files
with
18 additions
and
15 deletions
... | ... | @@ -26,8 +26,8 @@ |
26 | 26 | #ifndef __SERVER_H__ |
27 | 27 | #define __SERVER_H__ |
28 | 28 | |
29 | -#include <stdio.h> /* for printf() and fprintf() */ | |
30 | -#include <poll.h> /* for select system call and related */ | |
29 | +#include <stdio.h> // for printf() and fprintf() | |
30 | +#include <poll.h> // for poll system call and related | |
31 | 31 | |
32 | 32 | #include "class.h" |
33 | 33 | #include "socket.h" | ... | ... |
... | ... | @@ -46,9 +46,9 @@ ctor(void * _this, va_list * params) { |
46 | 46 | |
47 | 47 | this->hash = sdbm((unsigned char *)name); |
48 | 48 | |
49 | - this->value = malloc(sizeof(char*) * (++this->nvalue)); | |
50 | - this->value[this->nvalue - 1] = malloc(strlen(value) + 1); | |
51 | - strcpy(this->value[this->nvalue - 1], value); | |
49 | + this->value = malloc(sizeof(char*) * (++(this->nvalue))); | |
50 | + (this->value)[this->nvalue - 1] = malloc(strlen(value) + 1); | |
51 | + strcpy((this->value)[this->nvalue - 1], value); | |
52 | 52 | |
53 | 53 | return 0; |
54 | 54 | } | ... | ... |
... | ... | @@ -46,8 +46,11 @@ httpHeaderAdd(const HttpHeader * root, HttpHeader header) |
46 | 46 | HttpHeader * found = tsearch(header, (void **)root, comp); |
47 | 47 | |
48 | 48 | if (*found != header) { |
49 | - (*found)->value = realloc((*found)->value, sizeof(char) * (++(*found)->nvalue)); | |
50 | - (*found)->value[(*found)->nvalue - 1] = malloc(strlen(header->value) + 1); | |
49 | + (*found)->value = realloc( | |
50 | + (*found)->value, | |
51 | + sizeof(char*) * (++(*found)->nvalue)); | |
52 | + (*found)->value[(*found)->nvalue - 1] = malloc( | |
53 | + strlen((header->value)[0]) + 1); | |
51 | 54 | strcpy(((*found)->value)[(*found)->nvalue - 1], (header->value)[0]); |
52 | 55 | delete(&header); |
53 | 56 | } | ... | ... |
... | ... | @@ -76,7 +76,7 @@ httpResponseMe(int value) |
76 | 76 | new(HttpHeader, "Set-Cookie", "profession=\"coder\"")); |
77 | 77 | |
78 | 78 | message->type = HTTP_MESSAGE_BUFFERED; |
79 | - message->nbody = sizeof(RESP_DATA) - 1; | |
79 | + message->nbody = sizeof(RESP_DATA)-1-2; | |
80 | 80 | message->body = calloc(1, sizeof(RESP_DATA)-2); |
81 | 81 | sprintf(message->body, RESP_DATA, value); |
82 | 82 | ... | ... |
... | ... | @@ -88,12 +88,12 @@ main() |
88 | 88 | |
89 | 89 | close(shm); |
90 | 90 | |
91 | - /* Block SIGALRM */ | |
91 | + // Block SIGALRM | |
92 | 92 | sigemptyset(&block_these); |
93 | 93 | sigaddset(&block_these, SIGALRM); |
94 | 94 | sigprocmask(SIG_BLOCK, &block_these, &pause_mask); |
95 | 95 | |
96 | - /* Set up handler for SIGALRM */ | |
96 | + // Set up handler for SIGALRM | |
97 | 97 | sigemptyset(&s.sa_mask); |
98 | 98 | sigaddset(&s.sa_mask, SIGINT); |
99 | 99 | s.sa_flags = 0; | ... | ... |
... | ... | @@ -22,8 +22,8 @@ |
22 | 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
23 | 23 | */ |
24 | 24 | |
25 | -#include <stdio.h> /* for printf() and fprintf() */ | |
26 | -#include <unistd.h> /* for getopt */ | |
25 | +#include <stdio.h> // for printf() and fprintf() | |
26 | +#include <unistd.h> // for getopt | |
27 | 27 | #include <stdlib.h> |
28 | 28 | |
29 | 29 | ... | ... |
Please
register
or
login
to post a comment