mirror of
https://github.com/darkk/redsocks.git
synced 2025-08-29 21:25:30 +00:00
fix memory leak issues
This commit is contained in:
parent
a1e65e4ccb
commit
651754834f
@ -46,6 +46,13 @@ static void httpc_client_init(redsocks_client *client)
|
|||||||
client->state = httpc_new;
|
client->state = httpc_new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void httpc_instance_fini(redsocks_instance *instance)
|
||||||
|
{
|
||||||
|
http_auth *auth = (void*)(instance + 1);
|
||||||
|
free_null(auth->last_auth_query);
|
||||||
|
auth->last_auth_query = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static struct evbuffer *httpc_mkconnect(redsocks_client *client);
|
static struct evbuffer *httpc_mkconnect(redsocks_client *client);
|
||||||
|
|
||||||
extern const char *auth_request_header;
|
extern const char *auth_request_header;
|
||||||
@ -56,10 +63,13 @@ static char *get_auth_request_header(struct evbuffer *buf)
|
|||||||
char *line;
|
char *line;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
line = evbuffer_readline(buf);
|
line = evbuffer_readline(buf);
|
||||||
if (line == NULL || *line == '\0' || strchr(line, ':') == NULL)
|
if (line == NULL || *line == '\0' || strchr(line, ':') == NULL) {
|
||||||
|
free_null(line);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
if (strncasecmp(line, auth_request_header, strlen(auth_request_header)) == 0)
|
if (strncasecmp(line, auth_request_header, strlen(auth_request_header)) == 0)
|
||||||
return line;
|
return line;
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +109,7 @@ static void httpc_read_cb(struct bufferevent *buffev, void *_arg)
|
|||||||
redsocks_drop_client(client);
|
redsocks_drop_client(client);
|
||||||
dropped = 1;
|
dropped = 1;
|
||||||
} else {
|
} else {
|
||||||
|
free(line);
|
||||||
free_null(auth->last_auth_query);
|
free_null(auth->last_auth_query);
|
||||||
char *ptr = auth_request;
|
char *ptr = auth_request;
|
||||||
|
|
||||||
@ -272,6 +283,7 @@ relay_subsys http_connect_subsys =
|
|||||||
.readcb = httpc_read_cb,
|
.readcb = httpc_read_cb,
|
||||||
.writecb = httpc_write_cb,
|
.writecb = httpc_write_cb,
|
||||||
.init = httpc_client_init,
|
.init = httpc_client_init,
|
||||||
|
.instance_fini = httpc_instance_fini,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
|
/* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||||
|
23
http-relay.c
23
http-relay.c
@ -98,7 +98,7 @@ static int httpr_buffer_append(httpr_buffer *buff, const char *data, int len)
|
|||||||
|
|
||||||
static void httpr_client_init(redsocks_client *client)
|
static void httpr_client_init(redsocks_client *client)
|
||||||
{
|
{
|
||||||
httpr_client *httpr = (void*)(client +1);
|
httpr_client *httpr = (void*)(client + 1);
|
||||||
|
|
||||||
client->state = httpr_new;
|
client->state = httpr_new;
|
||||||
memset(httpr, 0, sizeof(*httpr));
|
memset(httpr, 0, sizeof(*httpr));
|
||||||
@ -108,21 +108,35 @@ static void httpr_client_init(redsocks_client *client)
|
|||||||
|
|
||||||
static void httpr_client_fini(redsocks_client *client)
|
static void httpr_client_fini(redsocks_client *client)
|
||||||
{
|
{
|
||||||
httpr_client *httpr = (void*)(client +1);
|
httpr_client *httpr = (void*)(client + 1);
|
||||||
|
|
||||||
|
free_null(httpr->firstline);
|
||||||
|
httpr->firstline = NULL;
|
||||||
|
free_null(httpr->host);
|
||||||
|
httpr->host = NULL;
|
||||||
httpr_buffer_fini(&httpr->client_buffer);
|
httpr_buffer_fini(&httpr->client_buffer);
|
||||||
httpr_buffer_fini(&httpr->relay_buffer);
|
httpr_buffer_fini(&httpr->relay_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void httpr_instance_fini(redsocks_instance *instance)
|
||||||
|
{
|
||||||
|
http_auth *auth = (void*)(instance + 1);
|
||||||
|
free_null(auth->last_auth_query);
|
||||||
|
auth->last_auth_query = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static char *get_auth_request_header(struct evbuffer *buf)
|
static char *get_auth_request_header(struct evbuffer *buf)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
line = evbuffer_readline(buf);
|
line = evbuffer_readline(buf);
|
||||||
if (line == NULL || *line == '\0' || strchr(line, ':') == NULL)
|
if (line == NULL || *line == '\0' || strchr(line, ':') == NULL) {
|
||||||
|
free_null(line);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
if (strncasecmp(line, auth_request_header, strlen(auth_request_header)) == 0)
|
if (strncasecmp(line, auth_request_header, strlen(auth_request_header)) == 0)
|
||||||
return line;
|
return line;
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +150,7 @@ static void httpr_relay_read_cb(struct bufferevent *buffev, void *_arg)
|
|||||||
|
|
||||||
redsocks_touch_client(client);
|
redsocks_touch_client(client);
|
||||||
|
|
||||||
|
httpr_buffer_fini(&httpr->relay_buffer);
|
||||||
httpr_buffer_init(&httpr->relay_buffer);
|
httpr_buffer_init(&httpr->relay_buffer);
|
||||||
|
|
||||||
if (client->state == httpr_request_sent) {
|
if (client->state == httpr_request_sent) {
|
||||||
@ -160,6 +175,7 @@ static void httpr_relay_read_cb(struct bufferevent *buffev, void *_arg)
|
|||||||
|
|
||||||
dropped = 1;
|
dropped = 1;
|
||||||
} else {
|
} else {
|
||||||
|
free(line);
|
||||||
char *auth_request = get_auth_request_header(buffev->input);
|
char *auth_request = get_auth_request_header(buffev->input);
|
||||||
|
|
||||||
if (!auth_request) {
|
if (!auth_request) {
|
||||||
@ -584,6 +600,7 @@ relay_subsys http_relay_subsys =
|
|||||||
.readcb = httpr_relay_read_cb,
|
.readcb = httpr_relay_read_cb,
|
||||||
.writecb = httpr_relay_write_cb,
|
.writecb = httpr_relay_write_cb,
|
||||||
.client_eof = httpr_client_eof,
|
.client_eof = httpr_client_eof,
|
||||||
|
.instance_fini = httpr_instance_fini,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
|
/* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
|
||||||
|
@ -807,6 +807,9 @@ static void redsocks_fini_instance(redsocks_instance *instance) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (instance->relay_ss->instance_fini)
|
||||||
|
instance->relay_ss->instance_fini(instance);
|
||||||
|
|
||||||
if (event_initialized(&instance->listener)) {
|
if (event_initialized(&instance->listener)) {
|
||||||
if (event_del(&instance->listener) != 0)
|
if (event_del(&instance->listener) != 0)
|
||||||
log_errno(LOG_WARNING, "event_del");
|
log_errno(LOG_WARNING, "event_del");
|
||||||
|
@ -23,6 +23,7 @@ typedef struct relay_subsys_t {
|
|||||||
evbuffercb writecb;
|
evbuffercb writecb;
|
||||||
void (*init)(struct redsocks_client_t *client);
|
void (*init)(struct redsocks_client_t *client);
|
||||||
void (*fini)(struct redsocks_client_t *client);
|
void (*fini)(struct redsocks_client_t *client);
|
||||||
|
void (*instance_fini)(struct redsocks_client_t *client);
|
||||||
// connect_relay (if any) is called instead of redsocks_connect_relay after client connection acceptance
|
// connect_relay (if any) is called instead of redsocks_connect_relay after client connection acceptance
|
||||||
void (*connect_relay)(struct redsocks_client_t *client);
|
void (*connect_relay)(struct redsocks_client_t *client);
|
||||||
// client_eof is called while relay is not set up but EOF from client is received
|
// client_eof is called while relay is not set up but EOF from client is received
|
||||||
|
Loading…
Reference in New Issue
Block a user