[Fdo-trac] [fdo-trac] #1017: OGR Provider: stop aliasing the connection as its own capability/info/property objects
FDO
trac_fdo at osgeo.org
Mon Oct 19 14:31:33 PDT 2026
#1017: OGR Provider: stop aliasing the connection as its own
capability/info/property objects
----------------------------+----------------------
Reporter: jng | Owner: jng
Type: defect | Status: assigned
Priority: major | Milestone: 4.2.0
Component: OGR Provider | Version:
Severity: 3 | Keywords:
External ID: |
----------------------------+----------------------
Providers/OGR/Src/Provider/OgrProvider.h:31-41 — OgrConnection derives
from
FdoIConnection, the eight capability interfaces, FdoIConnectionInfo and
FdoIConnectionPropertyDictionary. Every capability/info/dictionary getter
(OgrProvider.h:89-106, :515-526) returns FDO_SAFE_ADDREF(this) instead of
a
separate helper object, so a caller that treats those pointers as
independent
objects multiplies the connection's reference count up to eleven times.
All of those interfaces inherit FdoIDisposable non-virtually
(Fdo/Unmanaged/Inc/Common/IDisposable.h; one of them,
FdoIConnectionCapabilities,
is wholly pure). OGR therefore carries eleven dormant FdoIDisposable
counters and
overrides AddRef/Release/Dispose in the most-derived class with one hand-
rolled
int m_refCount incremented and decremented with plain ++/--
(OgrProvider.h:52-70).
That opts out of the locking-aware counting FdoIDisposable implements
(Fdo/Unmanaged/Src/Common/IDisposable.cpp:66) and of the house style used
by the
provider's own multi-interface helpers — SLT_IMPLEMENT_REFCOUNTING,
Providers/SQLite/Src/Provider/slt.h:98-121.
Result: a "pure virtual function call" (MSVC R6025) when a caller
enumerates
providers or reads a capability, and on teardown. While the object is
alive each
sub-object's vtable routes AddRef/Release/Dispose to OgrConnection's
overrides;
during construction and destruction the vptr reverts to the interface's
vtable,
where Release() resolves to FdoIDisposable's real implementation against
that
sub-object's own counter and Dispose() resolves to the pure stub. A
release that
arrives through one of the aliases in that window dispatches into
_purecall. The
multi-interface layout is what turns a use-after-release into R6025 rather
than an
access violation, and the non-atomic counter lets two threads reach that
window.
OGR is not the only provider with the aliasing shape: SltConnection
returns this
as FdoIConnectionInfo / FdoIConnectionPropertyDictionary
(SltProvider.h:198,222)
and SltCreateDataStore::GetDataStoreProperties() (SltCommands.h:1250-1253)
is a
third alias on the same connection. A fix confined to OGR leaves that path
open.
Proposed fix
1. Stop aliasing: add OgrConnectionCapabilities / OgrConnectionInfo /
OgrConnectionPropertyDictionary classes that hold a counted reference
to the
connection and return those from the getters — the shape already used
by
Providers/SDF/Src/Provider/SdfConnection.cpp:152-155 and
SltCapabilities
(Providers/SQLite/Src/Provider/SltCapabilities.h:30-37). A caller then
releases
a small helper instead of the connection.
2. Make the remaining shared counters thread-safe with unconditional
InterlockedIncrement/InterlockedDecrement (same return values,
behaviour
preserving). Copying slt.h verbatim does not help: it only interlocks
when
FdoIDisposable::GetGlobalThreadLockingFlag() is set, that global setter
is not
exported by Fdo.dll, and a provider cannot read the per-object flag
because
m_objectThreadLockingEnabled has no getter and m_refCount is private
(IDisposable.h:66,74,110).
3. Apply the same treatment to SltConnection's two aliases in the same
change set,
or file it as a follow-up rather than leaving it reachable.
Tests (must fail before the fix)
In Providers/OGR/Src/UnitTest, registered with the existing CppUnit
harness
(UnitTest.cpp) and added to UnitTest.vcxproj and CMakeLists.txt:
- Lifecycle repro: create a connection, take the connection's own
reference plus
its capability, FdoIConnectionInfo and connection-property-dictionary
aliases,
release the connection so its count reaches zero, then call through an
alias and
require the provider to survive (currently dispatches into _purecall).
- Client-shaped loop: repeat create -> read all eight capabilities plus
ConnectionInfo and ConnectionProperties -> dispose, asserting the
connection's
GetRefCount() returns to 1 before the final release.
- Concurrency variant: dispose the aliases from a second thread while the
owning
thread releases the connection, to exercise the non-atomic counter.
Each fixture must be leak-checked in a Debug build;
Providers/OGR/Src/UnitTest has
no _CRTDBG_MAP_ALLOC mapping, so enable the CRT leak report there first.
Validation
- OGR UnitTest.exe green in both configurations (Debug and Release trees),
with
the new fixtures passing and the existing
ConnectTests/SelectTests/InsertTests/
UpdateTests/DeleteTests/VrtTests results unchanged.
- No change to a shipped interface signature; OgrConnection and the new
helper
classes are provider-internal and OGR publishes no Inc tree, and
CreateConnection (OgrProvider.cpp:41) keeps its shape. Change lands in
both FDO
working copies, fdo-dbg and fdo-rel.
--
Ticket URL: <https://trac.osgeo.org/fdo/ticket/1017>
FDO <http://fdo.osgeo.org/>
Feature Data Objects
More information about the fdo-trac
mailing list