mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 21:17:18 +03:00
memory leak in AirPlay
This commit is contained in:
@@ -109,6 +109,7 @@ bool led_unconfig(int idx) {
|
||||
if (idx >= MAX_LED) return false;
|
||||
|
||||
if (leds[idx].timer) xTimerDelete(leds[idx].timer, BLOCKTIME);
|
||||
leds[idx].timer = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -102,10 +102,10 @@ struct raop_ctx_s *raop_create(struct in_addr host, char *name,
|
||||
struct raop_ctx_s *raop_create(struct in_addr host, char *name,
|
||||
unsigned char mac[6], int latency,
|
||||
raop_cmd_cb_t cmd_cb, raop_data_cb_t data_cb) {
|
||||
struct raop_ctx_s *ctx = malloc(sizeof(struct raop_ctx_s));
|
||||
struct raop_ctx_s *ctx = malloc(sizeof(struct raop_ctx_s));
|
||||
struct sockaddr_in addr;
|
||||
char id[64];
|
||||
|
||||
char id[64];
|
||||
|
||||
#ifdef WIN32
|
||||
socklen_t nlen = sizeof(struct sockaddr);
|
||||
char *txt[] = { "am=esp32", "tp=UDP", "sm=false", "sv=false", "ek=1",
|
||||
@@ -167,21 +167,20 @@ struct raop_ctx_s *raop_create(struct in_addr host, char *name,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
getsockname(ctx->sock, (struct sockaddr *) &addr, &nlen);
|
||||
ctx->port = ntohs(addr.sin_port);
|
||||
ctx->port = ntohs(addr.sin_port);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
ctx->running = true;
|
||||
ctx->running = true;
|
||||
|
||||
memcpy(ctx->mac, mac, 6);
|
||||
snprintf(id, 64, "%02X%02X%02X%02X%02X%02X@%s", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], name);
|
||||
|
||||
memcpy(ctx->mac, mac, 6);
|
||||
|
||||
snprintf(id, 64, "%02X%02X%02X%02X%02X%02X@%s", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], name);
|
||||
|
||||
#ifdef WIN32
|
||||
// seems that Windows snprintf does not add NULL char if actual size > max
|
||||
id[63] = '\0';
|
||||
ctx->svc = mdnsd_register_svc(ctx->svr, id, "_raop._tcp.local", ctx->port, NULL, (const char**) txt);
|
||||
pthread_create(&ctx->thread, NULL, &rtsp_thread, ctx);
|
||||
|
||||
#else
|
||||
@@ -366,13 +365,13 @@ static bool handle_rtsp(raop_ctx_t *ctx, int sock)
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
sock = -1;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static bool handle_rtsp(raop_ctx_t *ctx, int sock)
|
||||
{
|
||||
#ifndef WIN32
|
||||
char *buf = NULL, *body = NULL, method[16] = "";
|
||||
key_data_t headers[16], resp[8] = { {NULL, NULL} };
|
||||
int len;
|
||||
bool success = true;
|
||||
@@ -402,7 +401,7 @@ static bool handle_rtsp(raop_ctx_t *ctx, int sock)
|
||||
memset(p, 0, 32 - (p - data));
|
||||
p = rsa_apply((unsigned char*) data, 32, &n, RSA_MODE_AUTH);
|
||||
n = base64_encode(p, n, &data_b64);
|
||||
|
||||
|
||||
// remove padding as well (seems to be optional now)
|
||||
for (n = strlen(data_b64) - 1; n > 0 && data_b64[n] == '='; data_b64[n--] = '\0');
|
||||
|
||||
@@ -467,9 +466,9 @@ static bool handle_rtsp(raop_ctx_t *ctx, int sock)
|
||||
} else if (!strcmp(method, "SETUP") && ((buf = kd_lookup(headers, "Transport")) != NULL)) {
|
||||
char *p;
|
||||
rtp_resp_t rtp = { 0 };
|
||||
// on announce, search remote
|
||||
short unsigned tport = 0, cport = 0;
|
||||
|
||||
if ((buf = kd_lookup(headers, "DACP-ID")) != NULL) strcpy(ctx->active_remote.DACPid, buf);
|
||||
// we are about to stream, do something if needed
|
||||
ctx->cmd_cb(RAOP_SETUP, NULL);
|
||||
|
||||
if ((p = strcasestr(buf, "timing_port")) != NULL) sscanf(p, "%*[^=]=%hu", &tport);
|
||||
@@ -672,7 +671,7 @@ static char *rsa_apply(unsigned char *input, int inlen, int *outlen, int mode)
|
||||
RSA_PKCS1_PADDING);
|
||||
break;
|
||||
case RSA_MODE_KEY:
|
||||
|
||||
*outlen = RSA_private_decrypt(inlen, input, out, rsa,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
#define RTP_SYNC (0x01)
|
||||
#define NTP_SYNC (0x02)
|
||||
|
||||
#define RESEND_TO 200
|
||||
#define RESEND_TO 200
|
||||
|
||||
enum { DATA = 0, CONTROL, TIMING };
|
||||
|
||||
@@ -159,7 +159,7 @@ static int seq_order(seq_t a, seq_t b);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static alac_file* alac_init(int fmtp[32]) {
|
||||
alac_file *alac;
|
||||
alac_file *alac;
|
||||
int sample_size = fmtp[3];
|
||||
|
||||
if (sample_size != 16) {
|
||||
@@ -257,7 +257,7 @@ rtp_resp_t rtp_init(struct in_addr host, int latency, char *aeskey, char *aesiv,
|
||||
|
||||
// create http port and start listening
|
||||
resp.cport = ctx->rtp_sockets[CONTROL].lport;
|
||||
resp.tport = ctx->rtp_sockets[TIMING].lport;
|
||||
resp.tport = ctx->rtp_sockets[TIMING].lport;
|
||||
resp.aport = ctx->rtp_sockets[DATA].lport;
|
||||
|
||||
if (rc) {
|
||||
@@ -291,13 +291,14 @@ void rtp_end(rtp_t *ctx)
|
||||
#else
|
||||
ctx->joiner = xTaskGetCurrentTaskHandle();
|
||||
xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
for (i = 0; i < 3; i++) closesocket(ctx->rtp_sockets[i].sock);
|
||||
|
||||
|
||||
delete_alac(ctx->alac_codec);
|
||||
if (ctx->decrypt_buf) free(ctx->decrypt_buf);
|
||||
|
||||
pthread_mutex_destroy(&ctx->ab_mutex);
|
||||
buffer_release(ctx->audio_buffer);
|
||||
|
||||
free(ctx);
|
||||
@@ -374,7 +375,7 @@ static void alac_decode(rtp_t *ctx, s16_t *dest, char *buf, int len, int *outsiz
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void alac_decode(rtp_t *ctx, s16_t *dest, char *buf, int len, int *outsize) {
|
||||
unsigned char iv[16];
|
||||
int aeslen;
|
||||
int aeslen;
|
||||
assert(len<=MAX_PACKET);
|
||||
|
||||
if (ctx->decrypt) {
|
||||
|
||||
@@ -377,7 +377,7 @@ bool http_parse(int sock, char *method, key_data_t *rkd, char **body, int *len)
|
||||
// line folding should be deprecated
|
||||
if (i && rkd[i].key && (line[0] == ' ' || line[0] == '\t')) {
|
||||
for(j = 0; j < strlen(line); j++) if (line[j] != ' ' && line[j] != '\t') break;
|
||||
rkd[i].data = realloc(rkd[i].data, strlen(rkd[i].data) + strlen(line + j) + 1);
|
||||
rkd[i].data = realloc(rkd[i].data, strlen(rkd[i].data) + strlen(line + j) + 1);
|
||||
strcat(rkd[i].data, line + j);
|
||||
continue;
|
||||
}
|
||||
@@ -403,7 +403,7 @@ bool http_parse(int sock, char *method, key_data_t *rkd, char **body, int *len)
|
||||
if (*len) {
|
||||
int size = 0;
|
||||
|
||||
*body = malloc(*len + 1);
|
||||
*body = malloc(*len + 1);
|
||||
while (*body && size < *len) {
|
||||
int bytes = recv(sock, *body + size, *len - size, 0);
|
||||
if (bytes <= 0) break;
|
||||
|
||||
Reference in New Issue
Block a user