On 06/16/2016 07:35 PM, Dimitry Sibiryakov wrote:
>     Hello, All.
>
>     Currently GPRE used to generate code like this:
>
>> static Firebird::IRequest*
>>     fb_396 = 0;              /* request handle */
>>
>>      for (int retries = 0; retries < 2; ++retries)
>>         {
>>         {
>>         if (!DB)
>>            DB = fbProvider->attachDatabase(fbStatus, 
>> isqlGlob.global_Db_name, 0, NULL);
>>         if (DB && !fbTrans)
>>            fbTrans = DB->startTransaction(fbStatus, 0, NULL);
>>         }
>>             if (!fb_396 && fbTrans && DB)
>>                fb_396 = DB->compileRequest(fbStatus, sizeof(fb_397), fb_397);
>>         if (fbTrans && fb_396)
>>                fb_396->start(fbStatus, fbTrans, 0);
>>             if (fbStatus->getErrors()[1] == isc_bad_req_handle) { 
>> fb_396->release(); fb_396 = NULL; }
>>         else break;
>>         }
>>      if (!(fbStatus->getState() & Firebird::IStatus::STATE_ERRORS)) {
>     But if between two calls of this code database was disconnected, memory, 
> allocated for
> fb_396 can be already freed

It can't - this is reference counted object. This is what you miss.

> , so call of fb_396->start() result in crash.
>     Consider, for example, following script:
>
>> connect a;
>> show generators;
>> commit;
>> connect b;
>> show generators;
>     Why it doesn't crash? Pure luck or there is protection that I don't see?
>

This is reference counted object, and it will not be actually deleted as 
long as

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports. http://sdm.link/zohomanageengine
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to