module-rtp: fix some memory leaks

This commit is contained in:
Wim Taymans 2023-02-21 19:16:23 +01:00
parent e010559ffe
commit a015edb934
3 changed files with 31 additions and 21 deletions

View file

@ -203,7 +203,6 @@ struct node {
struct session *session; struct session *session;
}; };
struct impl { struct impl {
struct pw_properties *props; struct pw_properties *props;
@ -295,6 +294,9 @@ static void session_free(struct session *sess)
spa_list_remove(&sess->link); spa_list_remove(&sess->link);
impl->n_sessions++; impl->n_sessions++;
} }
if (sess->node && sess->node->session != NULL)
sess->node->session = NULL;
pw_properties_free(sess->props); pw_properties_free(sess->props);
clear_sdp_info(&sess->info); clear_sdp_info(&sess->info);
free(sess); free(sess);
@ -513,7 +515,7 @@ static void send_sap(struct impl *impl, struct session *sess, bool bye)
spa_strbuf_append(&buf, "a=mediaclk:sender\n"); spa_strbuf_append(&buf, "a=mediaclk:sender\n");
} }
pw_log_debug("sending SAP for %u", sess->node->id); pw_log_debug("sending SAP for %u %s", sess->node->id, buffer);
iov[3].iov_base = buffer; iov[3].iov_base = buffer;
iov[3].iov_len = strlen(buffer); iov[3].iov_len = strlen(buffer);
@ -732,7 +734,7 @@ static int rule_matched(void *data, const char *location, const char *action,
return res; return res;
} }
static struct session *session_new(struct impl *impl, const struct sdp_info *info) static struct session *session_new(struct impl *impl, struct sdp_info *info)
{ {
struct session *session; struct session *session;
struct pw_properties *props; struct pw_properties *props;
@ -749,8 +751,10 @@ static struct session *session_new(struct impl *impl, const struct sdp_info *inf
if (session == NULL) if (session == NULL)
return NULL; return NULL;
session->info = *info;
session->announce = false; session->announce = false;
session->info = *info;
spa_zero(*info);
info = &session->info;
props = pw_properties_new(NULL, NULL); props = pw_properties_new(NULL, NULL);
if (props == NULL) if (props == NULL)
@ -1067,6 +1071,7 @@ static int parse_sap(struct impl *impl, void *data, size_t len)
else else
session_touch(sess); session_touch(sess);
} }
clear_sdp_info(&info);
return res; return res;
} }
@ -1165,9 +1170,7 @@ static void
proxy_removed(void *data) proxy_removed(void *data)
{ {
struct node *n = data; struct node *n = data;
pw_log_info("node %d removed", n->id); pw_log_debug("node %d removed", n->id);
if (n->session != NULL)
session_free(n->session);
pw_proxy_destroy(n->proxy); pw_proxy_destroy(n->proxy);
} }
@ -1175,12 +1178,18 @@ static void
proxy_destroy(void *data) proxy_destroy(void *data)
{ {
struct node *n = data; struct node *n = data;
pw_log_info("node %d destroy", n->id); pw_log_debug("node %d destroy", n->id);
spa_hook_remove(&n->node_listener); spa_hook_remove(&n->node_listener);
spa_hook_remove(&n->proxy_listener); spa_hook_remove(&n->proxy_listener);
n->proxy = NULL; n->proxy = NULL;
if (n->info) if (n->session != NULL) {
session_free(n->session);
n->session = NULL;
}
if (n->info) {
pw_node_info_free(n->info); pw_node_info_free(n->info);
n->info = NULL;
}
} }
static const struct pw_proxy_events proxy_events = { static const struct pw_proxy_events proxy_events = {

View file

@ -152,10 +152,11 @@ static const struct spa_dict_item module_info[] = {
}; };
struct impl { struct impl {
struct pw_context *context;
struct pw_impl_module *module; struct pw_impl_module *module;
struct spa_hook module_listener; struct spa_hook module_listener;
struct pw_properties *props; struct pw_properties *props;
struct pw_context *module_context;
struct pw_loop *loop; struct pw_loop *loop;
@ -200,7 +201,7 @@ struct impl {
uint16_t seq; uint16_t seq;
uint32_t ssrc; uint32_t ssrc;
uint32_t ts_offset; uint32_t ts_offset;
char ts_refclk[64]; char *ts_refclk;
struct spa_ringbuffer ring; struct spa_ringbuffer ring;
uint8_t buffer[BUFFER_SIZE]; uint8_t buffer[BUFFER_SIZE];
@ -790,6 +791,7 @@ static void impl_destroy(struct impl *impl)
pw_properties_free(impl->props); pw_properties_free(impl->props);
free(impl->ifname); free(impl->ifname);
free(impl->ts_refclk);
free(impl->session_name); free(impl->session_name);
free(impl); free(impl);
} }
@ -929,7 +931,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
impl->stream_props = stream_props; impl->stream_props = stream_props;
impl->module = module; impl->module = module;
impl->module_context = context; impl->context = context;
impl->loop = pw_context_get_main_loop(context); impl->loop = pw_context_get_main_loop(context);
if (pw_properties_get(props, PW_KEY_NODE_VIRTUAL) == NULL) if (pw_properties_get(props, PW_KEY_NODE_VIRTUAL) == NULL)
@ -1037,8 +1039,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
impl->ts_offset = ts_offset < 0 ? rand() : ts_offset; impl->ts_offset = ts_offset < 0 ? rand() : ts_offset;
str = pw_properties_get(props, "sess.ts-refclk"); str = pw_properties_get(props, "sess.ts-refclk");
if (str != NULL) impl->ts_refclk = str ? strdup(str) : NULL;
snprintf(impl->ts_refclk, sizeof(impl->ts_refclk), "%s", str);
str = pw_properties_get(props, "sess.min-ptime"); str = pw_properties_get(props, "sess.min-ptime");
if (!spa_atof(str, &impl->min_ptime)) if (!spa_atof(str, &impl->min_ptime))
@ -1077,13 +1078,13 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
if (impl->info.info.raw.channels > 0) if (impl->info.info.raw.channels > 0)
pw_properties_setf(stream_props, "rtp.channels", "%u", impl->info.info.raw.channels); pw_properties_setf(stream_props, "rtp.channels", "%u", impl->info.info.raw.channels);
pw_properties_setf(stream_props, "rtp.ts-offset", "%u", impl->ts_offset); pw_properties_setf(stream_props, "rtp.ts-offset", "%u", impl->ts_offset);
if (impl->ts_refclk[0]) if (impl->ts_refclk != NULL)
pw_properties_set(stream_props, "rtp.ts-refclk", impl->ts_refclk); pw_properties_set(stream_props, "rtp.ts-refclk", impl->ts_refclk);
impl->core = pw_context_get_object(impl->module_context, PW_TYPE_INTERFACE_Core); impl->core = pw_context_get_object(impl->context, PW_TYPE_INTERFACE_Core);
if (impl->core == NULL) { if (impl->core == NULL) {
str = pw_properties_get(props, PW_KEY_REMOTE_NAME); str = pw_properties_get(props, PW_KEY_REMOTE_NAME);
impl->core = pw_context_connect(impl->module_context, impl->core = pw_context_connect(impl->context,
pw_properties_new( pw_properties_new(
PW_KEY_REMOTE_NAME, str, PW_KEY_REMOTE_NAME, str,
NULL), NULL),

View file

@ -135,7 +135,7 @@ struct impl {
struct pw_impl_module *module; struct pw_impl_module *module;
struct spa_hook module_listener; struct spa_hook module_listener;
struct pw_properties *props; struct pw_properties *props;
struct pw_context *module_context; struct pw_context *context;
struct pw_loop *loop; struct pw_loop *loop;
struct pw_loop *data_loop; struct pw_loop *data_loop;
@ -1122,7 +1122,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
} }
impl->module = module; impl->module = module;
impl->module_context = context; impl->context = context;
impl->loop = pw_context_get_main_loop(context); impl->loop = pw_context_get_main_loop(context);
impl->data_loop = pw_data_loop_get_loop(pw_context_get_data_loop(context)); impl->data_loop = pw_data_loop_get_loop(pw_context_get_data_loop(context));
@ -1241,10 +1241,10 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
pw_properties_setf(stream_props, PW_KEY_NODE_LATENCY, "%d/%d", pw_properties_setf(stream_props, PW_KEY_NODE_LATENCY, "%d/%d",
impl->target_buffer / 2, impl->rate); impl->target_buffer / 2, impl->rate);
impl->core = pw_context_get_object(impl->module_context, PW_TYPE_INTERFACE_Core); impl->core = pw_context_get_object(impl->context, PW_TYPE_INTERFACE_Core);
if (impl->core == NULL) { if (impl->core == NULL) {
str = pw_properties_get(props, PW_KEY_REMOTE_NAME); str = pw_properties_get(props, PW_KEY_REMOTE_NAME);
impl->core = pw_context_connect(impl->module_context, impl->core = pw_context_connect(impl->context,
pw_properties_new( pw_properties_new(
PW_KEY_REMOTE_NAME, str, PW_KEY_REMOTE_NAME, str,
NULL), NULL),