Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak in cg_rocket_datasource.cpp #1148

Open
Dimitriio opened this issue Jan 7, 2020 · 1 comment
Open

Possible memory leak in cg_rocket_datasource.cpp #1148

Dimitriio opened this issue Jan 7, 2020 · 1 comment

Comments

@Dimitriio
Copy link
Contributor

@Dimitriio Dimitriio commented Jan 7, 2020

I was reading some code in cg_rocket_datasource.cpp I saw this method :

void CG_Rocket_CleanUpServerList( const char *table )
{
	int i;
	int j;
	int netSrc = CG_StringToNetSource( table );

	for ( i = AS_LOCAL; i <= AS_FAVORITES; ++i )
	{
		if ( !table || !*table || i == netSrc )
		{
			for ( j = 0; j < rocketInfo.data.serverCount[ i ]; ++j )
			{
				BG_Free( rocketInfo.data.servers[ i ][ j ].name );
				BG_Free( rocketInfo.data.servers[ i ][ j ].label );
				BG_Free( rocketInfo.data.servers[ i ][ j ].addr );
				BG_Free( rocketInfo.data.servers[ i ][ j ].mapName );
				rocketInfo.data.serverCount[ i ] = 0;
			}
		}
	}
}

Should the line rocketInfo.data.serverCount[ i ] = 0; be oustide the "for loop" like that :

void CG_Rocket_CleanUpServerList( const char *table )
{
	int i;
	int j;
	int netSrc = CG_StringToNetSource( table );

	for ( i = AS_LOCAL; i <= AS_FAVORITES; ++i )
	{
		if ( !table || !*table || i == netSrc )
		{
			for ( j = 0; j < rocketInfo.data.serverCount[ i ]; ++j )
			{
				BG_Free( rocketInfo.data.servers[ i ][ j ].name );
				BG_Free( rocketInfo.data.servers[ i ][ j ].label );
				BG_Free( rocketInfo.data.servers[ i ][ j ].addr );
				BG_Free( rocketInfo.data.servers[ i ][ j ].mapName );
			}
			rocketInfo.data.serverCount[ i ] = 0;
		}
	}
}

I feel that for now we just iterate on the first element of the list which create a small memory leak.

@DolceTriade

This comment has been minimized.

Copy link
Member

@DolceTriade DolceTriade commented Jan 7, 2020

You are correct. If you would like to submit a PR feel free, otherwise we will fix it. Thanks!

Dimitriio added a commit to Dimitriio/Unvanquished that referenced this issue Jan 7, 2020
Fix issue Unvanquished#1148
Dimitriio added a commit to Dimitriio/Unvanquished that referenced this issue Jan 7, 2020
slipher added a commit that referenced this issue Jan 7, 2020
Fix issue #1148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.