gpt4 book ai didi

sql-server - 为什么这个带有 DBI 连接到 MS SQL 服务器的 perl 程序通过 ODBC 泄漏内存?

转载 作者:可可西里 更新时间:2023-11-01 10:28:56 26 4
gpt4 key购买 nike

我在工作中维护了几个 Perl 程序,这些程序多年来在各种系统(WinXP、Win 2003、Linux)上运行良好。最近我们在运行 SQL Server 2008 的 64 位 Windows 2008 Server 上为一个新客户端部署了它们。代码运行得很好,然后就停止了。查看它,我发现我遇到了内存不足的错误。为了追踪泄漏,我想出了以下示例程序,该程序在一两分钟内声明了大约 40 兆的内存,并且还在不断增长。有什么想法吗?

use strict;
use warnings;
use DBI qw(:sql_types);

my $dbh = DBI->connect("DBI:ODBC:sample_db", "user", "pass");
my $query = $dbh->prepare("SELECT TOP 1 ID FROM TABLE");

while (1)
{
$query->execute();
while (my $row = $query->fetchrow_hashref() ){
print $row->{ID} . "\n";
}
$query->finish();
}

我正在运行 strawberry perl 5.12.2,但也能够在这个带有 5.10 版本的盒子上重现它。

C:>perl -V
Summary of my perl5 (revision 5 version 12 subversion 2) configuration:

Platform:
osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
uname='Win32 strawberryperl 5.12.2.0 #1 Fri Nov 5 05:17:27 2010 i386'
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags =' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -
DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields -
DPERL_MSVC`enter code here`RT_READFIX',
optimize='-s -O2',
cppflags='-DWIN32'
ccversion='', gccversion='4.4.3', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long long', lseek
size=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++', ldflags ='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\li
b"'
libpth=C:\strawberry\c\lib C:\strawberry\c\i686-w64-mingw32\lib
libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32
-lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion
-lodbc32 -lodbccp32 -lcomctl32
perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladva
pi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lver
sion -lodbc32 -lodbccp32 -lcomctl32
libc=, so=dll, useshrplib=true, libperl=libperl512.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\st
rawberry\c\lib"'


Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_ITHREADS
USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF
USE_SITECUSTOMIZE
Built under MSWin32
Compiled at Nov 5 2010 08:39:08
@INC:
C:/strawberry/perl/site/lib
C:/strawberry/perl/vendor/lib
C:/strawberry/perl/lib
.

最佳答案

1.24_2 中引入了漏洞,直到 1.26_3 才修复。来自更改文件:

=head2 DBD::ODBC 1.26_3 2010 年 11 月 18 日的更改

已修复 rt 63108。1.24_2 中对列绑定(bind)的更改不是 完成并导致绑定(bind)列在每次执行时反弹 浪费时间和内存泄漏。发现、诊断和建议修复 史蒂夫·本特利 (Steve Bentley) 着。

发生这种情况时,总是值得检查您使用的模块的变更日志。

关于sql-server - 为什么这个带有 DBI 连接到 MS SQL 服务器的 perl 程序通过 ODBC 泄漏内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5264652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com