mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	protocol-native: don't remove all fds in clear
When we consumed all the buffer data, don't clear all the fds but only those that were already consumed in the message. It is possible that we already have fds for the next message and we don't want to discard those. Fixes some intermittend memory map errors.
This commit is contained in:
		
							parent
							
								
									0ac465854b
								
							
						
					
					
						commit
						9eb1633b02
					
				
					 2 changed files with 13 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -199,8 +199,8 @@ static void debug_msg(const char *prefix, const struct pw_protocol_native_messag
 | 
			
		|||
{
 | 
			
		||||
	struct spa_pod *pod;
 | 
			
		||||
	pw_logt_debug(mod_topic_connection,
 | 
			
		||||
		      "%s: id:%d op:%d size:%d seq:%d", prefix,
 | 
			
		||||
		      msg->id, msg->opcode, msg->size, msg->seq);
 | 
			
		||||
		      "%s: id:%d op:%d size:%d seq:%d fds:%d", prefix,
 | 
			
		||||
		      msg->id, msg->opcode, msg->size, msg->seq, msg->n_fds);
 | 
			
		||||
 | 
			
		||||
	if ((pod = get_first_pod_from_data(msg->data, msg->size, 0)) != NULL)
 | 
			
		||||
		spa_debug_pod(0, NULL, pod);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -271,16 +271,22 @@ too_many_fds:
 | 
			
		|||
static void clear_buffer(struct buffer *buf, bool fds)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
 | 
			
		||||
	pw_log_debug("clear fds:%d", fds);
 | 
			
		||||
	if (fds) {
 | 
			
		||||
		for (i = 0; i < buf->n_fds; i++) {
 | 
			
		||||
			pw_log_debug("%p: close fd:%d", buf, buf->fds[i]);
 | 
			
		||||
			close(buf->fds[i]);
 | 
			
		||||
		}
 | 
			
		||||
		buf->n_fds = 0;
 | 
			
		||||
		buf->fds_offset = 0;
 | 
			
		||||
	} else {
 | 
			
		||||
		buf->n_fds -= SPA_MIN(buf->fds_offset, buf->n_fds);
 | 
			
		||||
		memmove(buf->fds, &buf->fds[buf->fds_offset], buf->n_fds * sizeof(int));
 | 
			
		||||
		buf->fds_offset = 0;
 | 
			
		||||
	}
 | 
			
		||||
	buf->n_fds = 0;
 | 
			
		||||
	buf->buffer_size = 0;
 | 
			
		||||
	buf->offset = 0;
 | 
			
		||||
	buf->fds_offset = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** Prepare connection for calling from reentered context.
 | 
			
		||||
| 
						 | 
				
			
			@ -711,8 +717,9 @@ pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
 | 
			
		|||
 | 
			
		||||
	if (mod_topic_connection->level >= SPA_LOG_LEVEL_DEBUG) {
 | 
			
		||||
		pw_logt_debug(mod_topic_connection,
 | 
			
		||||
			">>>>>>>>> out: id:%d op:%d size:%d seq:%d",
 | 
			
		||||
				buf->msg.id, buf->msg.opcode, size, buf->msg.seq);
 | 
			
		||||
			">>>>>>>>> out: id:%d op:%d size:%d seq:%d fds:%d",
 | 
			
		||||
				buf->msg.id, buf->msg.opcode, size, buf->msg.seq,
 | 
			
		||||
				buf->msg.n_fds);
 | 
			
		||||
	        spa_debug_pod(0, NULL, SPA_PTROFF(p, impl->hdr_size, struct spa_pod));
 | 
			
		||||
		pw_logt_debug(mod_topic_connection,
 | 
			
		||||
			">>>>>>>>> out: done");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue