This project is read-only.

memory exception when calling sql_next_result


SQL serer library: php_sqlsrv.dll, version 3
PHP: 5.4 & 5.5


When calling sql_next_result we get a memory exception. The exception is caused by the code in

sqlsrv_error* odbc_get_diag_rec( sqlsrv_stmt* odbc, SQLSMALLINT record_number )

attempting to free a stack based char buffer.

The problem occurs when convert_string_from_utf16 does not convert the SQL message (in our case a warning derived from a sql server print statement). If it is not converted the char pointer in odbc_get_diag_rec still refers to a stack variable instead of the new convert_string char pointer. On exit of the function odbc_get_diag_rec causes a memory exception.

I have attached the code before and after my fix. The code was downloaded from the source code link on the 19/02/2014

Charles Durrant
Thomson Reuters

file attachments