Skip to content

ODBC: Infinite loop on error #194

Description

@Bilal2453

Lua version: tested on 5.4 and 5.1 and Luajit.
Driver: ODBC (unixODBC).
Backend: FreeTDS 7.4.
System: Linux (Fedora 43).

The following invalid code:

local conn = assert(env:connect('TestConn', 'username', 'password'))
local stmt = assert(conn:prepare('SELECT DOCNUM FROM [My-Db].dbo.INVOICED;'))
local cur = stmt:execute()

for docno in cur.fetch, cur do
  print(docno)
end

cur:close()

cur = stmt:execute()
cur = stmt:execute() -- the culprit
print(cur)

Produces the following output:

0
1
2
...
4
unixODBC: API Error, env handle used after being free
unixODBC: API Error, env handle used after being free
unixODBC: API Error, env handle used after being free
unixODBC: API Error, env handle used after being free
unixODBC: API Error, env handle used after being free
[loops forever]

Expected behaviour?
It errors once and doesn't busy loop.

If it matters, my .odbc.ini file looks like this:

   [TestConn]
   Driver      = FreeTDS
   TDS_Version = 7.4
   Server      = 192.168.1.5
   Database    = My-Db
   Port        = 59650

Only really happens in those edge cases where the code itself is wrong, but it is worth mentioning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions