Skip to content

Commit 812759f

Browse files
committed
Avoid memory leak bug with msodbcsql
1 parent 4022e28 commit 812759f

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

ext/odbc/tests/odbc_connect_001.phpt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,40 @@ include 'skipif.inc';
1616
include 'config.inc';
1717
$dsn = str_replace(";uid={$user};pwd={$pass}", '', $dsn);
1818

19+
/*
20+
* A bug in msodbcsql causes a memory leak when reconnecting after closing.
21+
* Therefore, avoid closing it.
22+
*/
23+
1924
echo "dsn without credentials / correct user / correct password\n";
2025
$conn = odbc_connect($dsn, $user, $pass);
2126
echo $conn ? "Connected.\n\n" : "";
22-
if ($conn) odbc_close($conn);
27+
// if ($conn) odbc_close($conn);
2328

2429
echo "dsn with correct user / incorrect user / correct password\n";
2530
$conn = odbc_connect("{$dsn};uid={$user}", 'hoge', $pass);
2631
echo $conn ? "Connected.\n\n" : "";
27-
if ($conn) odbc_close($conn);
32+
// if ($conn) odbc_close($conn);
2833

2934
echo "dsn with correct password / correct user / incorrect password\n";
3035
$conn = odbc_connect("{$dsn};PWD={$pass}", $user, 'fuga');
3136
echo $conn ? "Connected.\n\n" : "";
32-
if ($conn) odbc_close($conn);
37+
// if ($conn) odbc_close($conn);
3338

3439
echo "dsn with correct credentials / incorrect user / incorrect password\n";
3540
$conn = odbc_connect("{$dsn};Uid={$user};pwD={$pass}", 'hoge', 'fuga');
3641
echo $conn ? "Connected.\n\n" : "";
37-
if ($conn) odbc_close($conn);
42+
// if ($conn) odbc_close($conn);
3843

3944
echo "dsn with correct credentials / null user / null password\n";
4045
$conn = odbc_connect("{$dsn};Uid={$user};pwD={$pass}", null, null);
4146
echo $conn ? "Connected.\n\n" : "";
42-
if ($conn) odbc_close($conn);
47+
// if ($conn) odbc_close($conn);
4348

4449
echo "dsn with correct credentials / not set user / not set password\n";
4550
$conn = odbc_connect("{$dsn};Uid={$user};pwD={$pass}");
4651
echo $conn ? "Connected.\n" : "";
47-
if ($conn) odbc_close($conn);
52+
// if ($conn) odbc_close($conn);
4853
?>
4954
--EXPECT--
5055
dsn without credentials / correct user / correct password

ext/pdo_odbc/tests/basic_connection.phpt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ $password = getenv('PDO_ODBC_TEST_PASS');
1919

2020
$dsn = str_replace(";uid={$user};pwd={$password}", '', $dsnWithCredentials);
2121

22+
/*
23+
* A bug in msodbcsql causes a memory leak when reconnecting after closing.
24+
* Therefore, avoid closing it.
25+
*/
26+
2227
echo "dsn without credentials / correct user / correct password\n";
2328
try {
2429
$db = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
2530
echo "Connected.\n\n";
26-
$db = null;
31+
// $db = null;
2732
} catch (PDOException $e) {
2833
echo $e->getMessage()."\n";
2934
}
@@ -32,7 +37,7 @@ echo "dsn with credentials / no user / no password\n";
3237
try {
3338
$db = new PDO("{$dsn};uid={$user};pwd={$password}", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
3439
echo "Connected.\n\n";
35-
$db = null;
40+
// $db = null;
3641
} catch (PDOException $e) {
3742
echo $e->getMessage()."\n";
3843
}
@@ -41,7 +46,7 @@ echo "dsn with correct user / incorrect user / correct password\n";
4146
try {
4247
$db = new PDO("{$dsn};UID={$user}", 'hoge', $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
4348
echo "Connected.\n\n";
44-
$db = null;
49+
// $db = null;
4550
} catch (PDOException $e) {
4651
echo $e->getMessage()."\n";
4752
}
@@ -50,7 +55,7 @@ echo "dsn with correct password / correct user / incorrect password\n";
5055
try {
5156
$db = new PDO("{$dsn};PWD={$password}", $user, 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
5257
echo "Connected.\n\n";
53-
$db = null;
58+
// $db = null;
5459
} catch (PDOException $e) {
5560
echo $e->getMessage()."\n";
5661
}
@@ -59,7 +64,7 @@ echo "dsn with correct credentials / incorrect user / incorrect password\n";
5964
try {
6065
$db = new PDO("{$dsn};Uid={$user};Pwd={$password}", 'hoge', 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
6166
echo "Connected.\n";
62-
$db = null;
67+
// $db = null;
6368
} catch (PDOException $e) {
6469
echo $e->getMessage()."\n";
6570
}

0 commit comments

Comments
 (0)