Rewrited #44: fixed memory error and leak

This commit is contained in:
Devaev Maxim
2020-09-19 16:55:39 +03:00
parent 653ebd6e88
commit 3dc083d2ef

View File

@@ -291,31 +291,27 @@ static int _http_preprocess_request(struct evhttp_request *request, struct http_
static void _http_callback_root(struct evhttp_request *request, void *v_server) {
struct http_server_t *server = (struct http_server_t *)v_server;
struct evbuffer *buf;
// Variables to make mjpg_streamer compatibility
const char *action;
struct evkeyvalq args;
// End
struct evkeyvalq params; // For mjpg-streamer compatibility
const char *action; // Ditto
PREPROCESS_REQUEST;
PREPROCESS_REQUEST;
// Variables to make mjpg_streamer compatibility
evhttp_parse_query(evhttp_request_get_uri(request), &args);
action = evhttp_find_header(&args, "action");
if ( strcmp( action, "snapshot" ) == 0 ) {
_http_callback_snapshot(request, (void *)v_server);
return;
}
if ( strcmp( action, "stream" ) == 0 ) {
_http_callback_stream(request, (void *)v_server);
return;
}
// End
evhttp_parse_query(evhttp_request_get_uri(request), &params);
action = evhttp_find_header(&params, "action");
assert((buf = evbuffer_new()));
assert(evbuffer_add_printf(buf, "%s", HTML_INDEX_PAGE));
ADD_HEADER("Content-Type", "text/html");
evhttp_send_reply(request, HTTP_OK, "OK", buf);
evbuffer_free(buf);
if (action && !strcmp(action, "snapshot")) {
_http_callback_snapshot(request, v_server);
} else if (action && !strcmp(action, "stream")) {
_http_callback_stream(request, v_server);
} else {
assert((buf = evbuffer_new()));
assert(evbuffer_add_printf(buf, "%s", HTML_INDEX_PAGE));
ADD_HEADER("Content-Type", "text/html");
evhttp_send_reply(request, HTTP_OK, "OK", buf);
evbuffer_free(buf);
}
evhttp_clear_headers(&params);
}
static void _http_callback_static(struct evhttp_request *request, void *v_server) {