http: fix potential memory corruption
This commit is contained in:
parent
e3a4d2768f
commit
e1a5f987c4
@ -8,7 +8,7 @@
|
|||||||
#include "device/buffer_lock.h"
|
#include "device/buffer_lock.h"
|
||||||
|
|
||||||
#define SNAPSHOT_TIMEOUT_MS 3000
|
#define SNAPSHOT_TIMEOUT_MS 3000
|
||||||
#define SNAPSHOT_DEFAULT_DELAY_PARAM "300"
|
#define SNAPSHOT_DEFAULT_DELAY_PARAM 300
|
||||||
|
|
||||||
#define PART_BOUNDARY "123456789000000000000987654321"
|
#define PART_BOUNDARY "123456789000000000000987654321"
|
||||||
#define CONTENT_TYPE "image/jpeg"
|
#define CONTENT_TYPE "image/jpeg"
|
||||||
@ -47,15 +47,18 @@ int http_snapshot_buf_part(buffer_lock_t *buf_lock, buffer_t *buf, int frame, ht
|
|||||||
|
|
||||||
void http_snapshot(http_worker_t *worker, FILE *stream)
|
void http_snapshot(http_worker_t *worker, FILE *stream)
|
||||||
{
|
{
|
||||||
|
int max_delay_value = SNAPSHOT_DEFAULT_DELAY_PARAM;
|
||||||
|
|
||||||
// passing the max_delay=0 will ensure that frame is capture at this exact moment
|
// passing the max_delay=0 will ensure that frame is capture at this exact moment
|
||||||
const char *max_delay = http_get_param(worker, "max_delay");
|
char *max_delay = http_get_param(worker, "max_delay");
|
||||||
if (!max_delay) {
|
if (max_delay) {
|
||||||
max_delay = SNAPSHOT_DEFAULT_DELAY_PARAM;
|
max_delay_value = atoi(max_delay);
|
||||||
|
free(max_delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
http_snapshot_t snapshot = {
|
http_snapshot_t snapshot = {
|
||||||
.stream = stream,
|
.stream = stream,
|
||||||
.start_time_us = get_monotonic_time_us(NULL, NULL) - atoi(max_delay) * 1000
|
.start_time_us = get_monotonic_time_us(NULL, NULL) - max_delay_value * 1000
|
||||||
};
|
};
|
||||||
|
|
||||||
int n = buffer_lock_write_loop(&snapshot_lock, 1, SNAPSHOT_TIMEOUT_MS,
|
int n = buffer_lock_write_loop(&snapshot_lock, 1, SNAPSHOT_TIMEOUT_MS,
|
||||||
|
@ -87,12 +87,12 @@ void *http_enum_params(http_worker_t *worker, FILE *stream, http_param_fn fn, vo
|
|||||||
static void *http_get_param_fn(struct http_worker_s *worker, FILE *stream, const char *key, const char *value, void *opaque)
|
static void *http_get_param_fn(struct http_worker_s *worker, FILE *stream, const char *key, const char *value, void *opaque)
|
||||||
{
|
{
|
||||||
if (!strcmp(key, opaque))
|
if (!strcmp(key, opaque))
|
||||||
return (void*)value;
|
return (void*)strdup(value);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *http_get_param(http_worker_t *worker, const char *key)
|
char *http_get_param(http_worker_t *worker, const char *key)
|
||||||
{
|
{
|
||||||
return http_enum_params(worker, NULL, http_get_param_fn, (void*)key);
|
return http_enum_params(worker, NULL, http_get_param_fn, (void*)key);
|
||||||
}
|
}
|
||||||
|
@ -62,4 +62,4 @@ void http_400(FILE *stream, const char *data);
|
|||||||
void http_404(FILE *stream, const char *data);
|
void http_404(FILE *stream, const char *data);
|
||||||
void http_500(FILE *stream, const char *data);
|
void http_500(FILE *stream, const char *data);
|
||||||
void *http_enum_params(http_worker_t *worker, FILE *stream, http_param_fn fn, void *opaque);
|
void *http_enum_params(http_worker_t *worker, FILE *stream, http_param_fn fn, void *opaque);
|
||||||
const char *http_get_param(http_worker_t *worker, const char *key);
|
char *http_get_param(http_worker_t *worker, const char *key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user