Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » MSSQL connection cause memory leak
icon9.gif  MSSQL connection cause memory leak [message #47838] Mon, 10 April 2017 09:01 Go to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
my application frequently attempts to connect to the database server.
see the pic:
index.php?t=getfile&id=5224&private=0

and the code:
	while(1)
	{
		MSSQLSession mssql;
		for(;;) {
			String cs = "Driver={SQL Server};";
			cs << "Server=" << "127.0.0.1" << ';';
			String h = "sa";
			if(IsNull(h))
				cs << "Trusted_Connection=Yes;";
			else {
				cs << "UID=" << h << ';';
			//	Cout() << "Password:";
				cs << "PWD=" << pass << ';';
			//	Cout() << "Database (empty for default):";
				h = "";
				if(IsNull(h))
					cs << "Database=" << h << ';';
			}
			Cout() << "Connect mssql:" << cs << "\n";
			if(!mssql.Connect(cs))
				Cout() << "Connect failed: " << mssql.GetLastError() << '\n';
			else
				break;
		}
	
		#ifdef _DEBUG
			mssql.SetTrace();
		#endif			
		
		//do some work
		Sleep(1000);
		
		mssql.Close();
	}
Re: MSSQL connection cause memory leak [message #47839 is a reply to message #47838] Mon, 10 April 2017 11:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13617
Registered: November 2005
Ultimate Member
Thanks, that is weird. Will look into it asap.
Re: MSSQL connection cause memory leak [message #47840 is a reply to message #47839] Mon, 10 April 2017 11:55 Go to previous messageGo to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
Yes, momoery increased when ODBCSession::Connect > SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);

but the ODBCSession::Close() > SQLFreeHandle(SQL_HANDLE_DBC, hdbc); seems no effect!
Re: MSSQL connection cause memory leak [message #47842 is a reply to message #47840] Mon, 10 April 2017 12:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13617
Registered: November 2005
Ultimate Member
Now looking at Close, maybe try to swap

		SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
		SQLFreeHandle(SQL_HANDLE_STMT, hstmt);


to

		SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
		SQLFreeHandle(SQL_HANDLE_DBC, hdbc);


(maybe it does not get freed because there is still statement in it...)
Re: MSSQL connection cause memory leak [message #47843 is a reply to message #47842] Mon, 10 April 2017 12:32 Go to previous messageGo to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
i debug again, i must correct my earlier comment,
is the
if(IsOk(SQLDriverConnect(hdbc, NULL, (SQLCHAR *)cs, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT))) {
...

cause memory increase, not SQLAllocHandle

the swap didn`t working Confused

Re: MSSQL connection cause memory leak [message #47844 is a reply to message #47843] Mon, 10 April 2017 12:47 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13617
Registered: November 2005
Ultimate Member
Maybe it needs

SQLDisconnect(hdbc);

before FreeHandle (in Close)?

Mirek
Re: MSSQL connection cause memory leak [message #47845 is a reply to message #47844] Mon, 10 April 2017 16:11 Go to previous messageGo to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
yes,you`re right! Twisted Evil

add
SQLDisconnect(hdbc);
before
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);

by the way,why not add "Close()" in "ODBCSession::~ODBCSession()"?
Re: MSSQL connection cause memory leak [message #47846 is a reply to message #47845] Mon, 10 April 2017 16:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13617
Registered: November 2005
Ultimate Member
akebee wrote on Mon, 10 April 2017 16:11
yes,you`re right! Twisted Evil

add
SQLDisconnect(hdbc);
before
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);

by the way,why not add "Close()" in "ODBCSession::~ODBCSession()"?


Perfect! Can you please, just to be sure, if the fix in trunk is OK?
Re: MSSQL connection cause memory leak [message #47850 is a reply to message #47846] Tue, 11 April 2017 03:12 Go to previous message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
yes its OK!
Previous Topic: How to connect to ODBC??
Next Topic: OleDB fails to build
Goto Forum:
  


Current Time: Sat May 21 14:22:16 CEST 2022

Total time taken to generate the page: 0.01963 seconds