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

@@ -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;
}