memory leak in AirPlay

This commit is contained in:
philippe44
2019-08-23 00:23:00 -07:00
parent 0ee2783b49
commit 8a0763cc27
4 changed files with 30 additions and 29 deletions

View File

@@ -109,6 +109,7 @@ bool led_unconfig(int idx) {
if (idx >= MAX_LED) return false; if (idx >= MAX_LED) return false;
if (leds[idx].timer) xTimerDelete(leds[idx].timer, BLOCKTIME); if (leds[idx].timer) xTimerDelete(leds[idx].timer, BLOCKTIME);
leds[idx].timer = NULL;
return true; return true;
} }

View File

@@ -104,8 +104,8 @@ struct raop_ctx_s *raop_create(struct in_addr host, char *name,
raop_cmd_cb_t cmd_cb, raop_data_cb_t data_cb) { 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; struct sockaddr_in addr;
char id[64]; char id[64];
#ifdef WIN32 #ifdef WIN32
socklen_t nlen = sizeof(struct sockaddr); socklen_t nlen = sizeof(struct sockaddr);
char *txt[] = { "am=esp32", "tp=UDP", "sm=false", "sv=false", "ek=1", 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; return NULL;
} }
} #ifdef WIN32
getsockname(ctx->sock, (struct sockaddr *) &addr, &nlen); getsockname(ctx->sock, (struct sockaddr *) &addr, &nlen);
ctx->port = ntohs(addr.sin_port); ctx->port = ntohs(addr.sin_port);
ctx->port = ntohs(addr.sin_port); #endif
#endif ctx->running = true;
memcpy(ctx->mac, mac, 6);
ctx->running = true; 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); #ifdef WIN32
// seems that Windows snprintf does not add NULL char if actual size > max
snprintf(id, 64, "%02X%02X%02X%02X%02X%02X@%s", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], name); 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); pthread_create(&ctx->thread, NULL, &rtsp_thread, ctx);
#else #else

View File

@@ -80,7 +80,7 @@
#define RTP_SYNC (0x01) #define RTP_SYNC (0x01)
#define NTP_SYNC (0x02) #define NTP_SYNC (0x02)
#define RESEND_TO 200 #define RESEND_TO 200
enum { DATA = 0, CONTROL, TIMING }; enum { DATA = 0, CONTROL, TIMING };
@@ -291,13 +291,14 @@ void rtp_end(rtp_t *ctx)
#else #else
ctx->joiner = xTaskGetCurrentTaskHandle(); ctx->joiner = xTaskGetCurrentTaskHandle();
xTaskNotifyWait(0, 0, NULL, portMAX_DELAY); xTaskNotifyWait(0, 0, NULL, portMAX_DELAY);
#endif #endif
}
} }
for (i = 0; i < 3; i++) closesocket(ctx->rtp_sockets[i].sock); 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); buffer_release(ctx->audio_buffer);
free(ctx); free(ctx);