Memory leak with SQLNumResultCols

Поиск
Список
Период
Сортировка
Искать

Memory leak with SQLNumResultCols

От:
Heikki Linnakangas <hlinnakangas@vmware.com>
Дата:
Вложения:
If you call SQLNumResultCols() on a non-SELECT statement, e.g. INSERT 
RETURNING, it leaks memory.

The root cause is that QR_Constructor() gets called multiple times due 
to multiple-evaluation of macro arguments. A the end of SC_pre_execute():

> 		if (!SC_is_pre_executable(self))
> 		{
> 			SC_set_Result(self, QR_Constructor());
> 			QR_set_rstatus(SC_get_Result(self), PORES_TUPLES_OK);
> 			self->inaccurate_result = TRUE;
> 			self->status = STMT_PREMATURE;
> 			num_fields = 0;
> 		}

SC_set_Result is a macro, which evaluates the 2nd argument multiple 
times, so we end up creating multiple result sets, most of which are leaked.

Multiple-evaluating macros are pretty dangerous. I think we should turn 
them into proper functions, per attached patch. This doesn't change all 
macros, only a few of the more complicated ones, and the one causing the 
leak in particular.

The attached patch is also available at my git repository at 
https://github.com/hlinnaka/psqlodbc/, along with a test case in 
master-with-testcases branch.

- Heikki
FAQ