Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in Microsoft ODBC Driver 17.10.5 for SQL Server #1488

Open
SakiTakamachi opened this issue Nov 7, 2023 · 4 comments
Open

Memory leak in Microsoft ODBC Driver 17.10.5 for SQL Server #1488

SakiTakamachi opened this issue Nov 7, 2023 · 4 comments

Comments

@SakiTakamachi
Copy link
Contributor

This is a report regarding a bug in the odbc driver. I'm writing here because I don't know the appropriate place to report it.

(I also posted it here. https://learn.microsoft.com/en-us/answers/questions/1418766/memory-leak-in-microsoft-odbc-driver-17-10-5-for-s)

The following code:

// odbc.c
#include <sql.h>
#include <sqlext.h>
#include <string.h>

int main(void) {
    HENV env;
    HDBC db;
    char *dsn = "Driver={ODBC Driver 17 for SQL Server};Server=sql-server;Port=1433;Database=test;uid=SA;pwd={/* pass */};"; // myenv
    SQLCHAR dsnbuf[1024];
    short dsnbuflen;

    SQLAllocEnv(&env);
    SQLAllocConnect(env, &db);
    SQLDriverConnect(db, NULL, (SQLCHAR*) dsn, strlen(dsn), dsnbuf, sizeof(dsnbuf) - 1, &dsnbuflen, SQL_DRIVER_NOPROMPT);

    SQLDisconnect(db);
    SQLFreeHandle(SQL_HANDLE_DBC, db);
    db = NULL;
    
    SQLFreeHandle(SQL_HANDLE_ENV, env);
    env = NULL;

    SQLAllocEnv(&env);
    SQLAllocConnect(env, &db);
    SQLDriverConnect(db, NULL, (SQLCHAR*) dsn, strlen(dsn), dsnbuf, sizeof(dsnbuf) - 1, &dsnbuflen, SQL_DRIVER_NOPROMPT);

    return 0;
}

compile command:

gcc -fsanitize=leak,undefined,address -fno-sanitize-recover -DZEND_TRACK_ARENA_ALLOC -Wall -o odbc odbc.c -lodbc

exec:

# ./odbc

=================================================================
==12092==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7fd55793e587 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:104
    #1 0x7fd5532728da  (/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.5.1+0x1808da)

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7fd55793e587 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:104
    #1 0x7fd5531fa909  (/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.5.1+0x108909)

SUMMARY: AddressSanitizer: 112 byte(s) leaked in 2 allocation(s).

In this way, once I close the connection and connect it again, I will get a memory leak.

Regards.

@v-makouz
Copy link
Contributor

v-makouz commented Nov 7, 2023

Which operating system are you running this on, and what's the version of unixODBC?

@SakiTakamachi
Copy link
Contributor Author

@v-makouz

ubuntu:20.04 (docker for mac)

# odbcinst --version
unixODBC 2.3.6

Regards.

@v-makouz
Copy link
Contributor

v-makouz commented Nov 8, 2023

I can reproduce the leak, and it looks like it was fixed in ODBC Driver 18. If possible, I would recommend using Driver 18, if not the next release of Driver 17 (with the fix) would probably be next year.

@SakiTakamachi
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants