mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
proxy: add refcount to keep the proxy alive in demarshal
We need to keep the proxy alive during demarshal because the callbacks might decide to destroy the proxy.
This commit is contained in:
parent
58fd46ebd1
commit
84ec90da2d
3 changed files with 21 additions and 4 deletions
|
|
@ -557,7 +557,11 @@ on_remote_data(void *data, int fd, uint32_t mask)
|
|||
this, msg->opcode, msg->id);
|
||||
continue;
|
||||
}
|
||||
if (demarshal[msg->opcode].func(proxy, msg) < 0) {
|
||||
proxy->refcount++;
|
||||
res = demarshal[msg->opcode].func(proxy, msg);
|
||||
pw_proxy_unref(proxy);
|
||||
|
||||
if (res < 0) {
|
||||
pw_log_error (NAME" %p: invalid message received %u for %u",
|
||||
this, msg->opcode, msg->id);
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -654,6 +654,7 @@ struct pw_proxy {
|
|||
struct pw_remote *remote; /**< the owner remote of this proxy */
|
||||
|
||||
uint32_t id; /**< client side id */
|
||||
int refcount;
|
||||
unsigned int zombie:1; /**< proxy is removed locally and waiting to
|
||||
* be removed from server */
|
||||
unsigned int removed:1; /**< proxy was removed from server */
|
||||
|
|
@ -910,6 +911,8 @@ int pw_control_remove_link(struct pw_control_link *link);
|
|||
|
||||
void pw_control_destroy(struct pw_control *control);
|
||||
|
||||
void pw_proxy_unref(struct pw_proxy *proxy);
|
||||
|
||||
/** \endcond */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ struct pw_proxy *pw_proxy_new(struct pw_proxy *factory,
|
|||
|
||||
this = &impl->this;
|
||||
this->remote = remote;
|
||||
this->refcount = 1;
|
||||
|
||||
this->marshal = pw_protocol_get_marshal(remote->conn->protocol, type);
|
||||
if (this->marshal == NULL) {
|
||||
|
|
@ -156,7 +157,6 @@ void pw_proxy_add_object_listener(struct pw_proxy *proxy,
|
|||
SPA_EXPORT
|
||||
void pw_proxy_destroy(struct pw_proxy *proxy)
|
||||
{
|
||||
struct proxy *impl = SPA_CONTAINER_OF(proxy, struct proxy, this);
|
||||
struct pw_remote *remote = proxy->remote;
|
||||
|
||||
if (!proxy->zombie) {
|
||||
|
|
@ -175,11 +175,21 @@ void pw_proxy_destroy(struct pw_proxy *proxy)
|
|||
}
|
||||
if (proxy->removed) {
|
||||
pw_map_remove(&remote->objects, proxy->id);
|
||||
pw_log_debug(NAME" %p: free %u", proxy, proxy->id);
|
||||
free(impl);
|
||||
|
||||
pw_proxy_unref(proxy);
|
||||
}
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
void pw_proxy_unref(struct pw_proxy *proxy)
|
||||
{
|
||||
if (--proxy->refcount > 0)
|
||||
return;
|
||||
|
||||
pw_log_debug(NAME" %p: free %u", proxy, proxy->id);
|
||||
free(proxy);
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
int pw_proxy_sync(struct pw_proxy *proxy, int seq)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue