Massive memory leaks on PAT change #264

Closed
opened 2026-01-29 16:39:22 +00:00 by claunia · 1 comment
Owner

Originally created by @cfsmp3 on GitHub (Jan 25, 2017).

Originally assigned to: @alexbrt on GitHub.

In general, the PAT on a transport stream doesn't change, as that would mean that a stream was added or removed, which it's an uncommon event.

But it can happen, and when it does we need to do proper clean up. What CCExtractor does in this case is clear the PMT table and mark all streams as "unseen", which forces all PMTs to be reloaded again. This was OK at some point in time, but it's not any more as when a program context is created a number of things happen (including OCR initialization).

So we need to do problem clean up. Otherwise we keep getting more and more resources and never free them.

This happens in ts_tables.c:

int parse_PAT (struct ccx_demuxer *ctx)
{
...
	if (ctx->last_pat_payload != NULL)
	{
		mprint ("Notice: PAT changed, clearing all variables.\n");
		dinit_cap(ctx);
		clear_PMT_array(ctx);
		memset (ctx->PIDs_seen,0,sizeof (int) *65536); // Forget all we saw
		if (!tlt_config.user_page) // If the user didn't select a page...
			tlt_config.page=0; // ..forget whatever we detected.

		gotpes=1;
	}
}

Assigning to @AlexBratosin2001 since he was the one fighting multiprogram, memory allocation, etc.

Originally created by @cfsmp3 on GitHub (Jan 25, 2017). Originally assigned to: @alexbrt on GitHub. In general, the PAT on a transport stream doesn't change, as that would mean that a stream was added or removed, which it's an uncommon event. But it _can_ happen, and when it does we need to do proper clean up. What CCExtractor does in this case is clear the PMT table and mark all streams as "unseen", which forces all PMTs to be reloaded again. This was OK at some point in time, but it's not any more as when a program context is created a number of things happen (including OCR initialization). So we need to do problem clean up. Otherwise we keep getting more and more resources and never free them. This happens in ts_tables.c: ``` int parse_PAT (struct ccx_demuxer *ctx) { ... if (ctx->last_pat_payload != NULL) { mprint ("Notice: PAT changed, clearing all variables.\n"); dinit_cap(ctx); clear_PMT_array(ctx); memset (ctx->PIDs_seen,0,sizeof (int) *65536); // Forget all we saw if (!tlt_config.user_page) // If the user didn't select a page... tlt_config.page=0; // ..forget whatever we detected. gotpes=1; } } ``` Assigning to @AlexBratosin2001 since he was the one fighting multiprogram, memory allocation, etc.
Author
Owner

@cfsmp3 commented on GitHub (Jan 25, 2017):

GSoC qualification: This gives 3 points.

@cfsmp3 commented on GitHub (Jan 25, 2017): GSoC qualification: This gives 3 points.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#264