mirror of
				https://github.com/aler9/rtsp-simple-server
				synced 2025-10-31 19:13:22 +08:00 
			
		
		
		
	rtsp source: fix memory leak in case source doesn't send H264 params in time
This commit is contained in:
		| @@ -328,19 +328,21 @@ func (s *rtspSource) handleMissingH264Params(c *gortsplib.Client, tracks gortspl | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	waitError := make(chan error) | 	readErr := make(chan error) | ||||||
| 	go func() { | 	go func() { | ||||||
| 		waitError <- c.Wait() | 		readErr <- c.Wait() | ||||||
| 	}() | 	}() | ||||||
|  |  | ||||||
| 	timeout := time.NewTimer(15 * time.Second) | 	timeout := time.NewTimer(15 * time.Second) | ||||||
| 	defer timeout.Stop() | 	defer timeout.Stop() | ||||||
|  |  | ||||||
| 	select { | 	select { | ||||||
| 	case err := <-waitError: | 	case err := <-readErr: | ||||||
| 		return err | 		return err | ||||||
|  |  | ||||||
| 	case <-timeout.C: | 	case <-timeout.C: | ||||||
|  | 		c.Close() | ||||||
|  | 		<-readErr | ||||||
| 		return fmt.Errorf("source did not send H264 parameters in time") | 		return fmt.Errorf("source did not send H264 parameters in time") | ||||||
|  |  | ||||||
| 	case <-paramsReceived: | 	case <-paramsReceived: | ||||||
| @@ -354,6 +356,8 @@ func (s *rtspSource) handleMissingH264Params(c *gortsplib.Client, tracks gortspl | |||||||
| 			tracks: tracks, | 			tracks: tracks, | ||||||
| 		}) | 		}) | ||||||
| 		if res.err != nil { | 		if res.err != nil { | ||||||
|  | 			c.Close() | ||||||
|  | 			<-readErr | ||||||
| 			return res.err | 			return res.err | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -368,9 +372,9 @@ func (s *rtspSource) handleMissingH264Params(c *gortsplib.Client, tracks gortspl | |||||||
| 		defer func() { | 		defer func() { | ||||||
| 			s.parent.onSourceStaticSetNotReady(pathSourceStaticSetNotReadyReq{source: s}) | 			s.parent.onSourceStaticSetNotReady(pathSourceStaticSetNotReadyReq{source: s}) | ||||||
| 		}() | 		}() | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return <-waitError | 		return <-readErr | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| // onSourceAPIDescribe implements source. | // onSourceAPIDescribe implements source. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 aler9
					aler9