Subject: | [WIN32] Safefree doesn't free calloc'ated memory correctly |
Some memory blocks in dbdimp.c are allocated via calloc(). This lead to segfault on Safefree() during testing on my win32 box. It is suggested in perlclib to use Newz macros instead of calloc() and such a replacement makes it work OK (see patch).
DBD-Pg-cvs
DBI-1.47
Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
Platform:
osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
usethreads=undef use5005threads=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='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DPERL_USE_SAFE_PUTENV -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
optimize='-MD -Zi -DNDEBUG -O1',
cppflags='-DWIN32'
ccversion='', gccversion='', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf -libpath:"c:\perl\lib\CORE" -machine:x86'
libpth=\lib
libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
gnulibc_version='undef'
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf -libpath:"c:\perl\lib\CORE" -machine:x86'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
Built under MSWin32
Compiled at Nov 1 2004 16:12:27
@INC:
C:/Perl/lib
C:/Perl/site/lib
.
--- dbdimp.c.orig Thu Mar 03 17:00:53 2005
+++ dbdimp.c Fri Mar 04 14:30:48 2005
@@ -1249,7 +1249,7 @@
else {
if (imp_sth->numbound) {
params = imp_sth->numphs;
- paramTypes = calloc(imp_sth->numphs, sizeof(*paramTypes));
+ Newz(0, paramTypes, imp_sth->numphs, Oid);
for (x=0,currph=imp_sth->ph; NULL != currph; currph=currph->nextph) {
paramTypes[x++] = currph->bind_type->type_id;
}
@@ -1539,7 +1539,7 @@
}
else { /* We are using a server that can handle PQexecParams/PQexecPrepared */
/* Put all values into an array to pass to PQexecPrepared */
- paramValues = calloc(imp_sth->numphs, sizeof(*paramValues));
+ Newz(0, paramValues, imp_sth->numphs, char *);
for (x=0,currph=imp_sth->ph; NULL != currph; currph=currph->nextph) {
paramValues[x++] = currph->value;
}
@@ -1547,8 +1547,8 @@
/* Binary or regular? */
if (imp_sth->has_binary) {
- paramLengths = calloc(imp_sth->numphs, sizeof(*paramLengths));
- paramFormats = calloc(imp_sth->numphs, sizeof(*paramFormats));
+ Newz(0, paramLengths, imp_sth->numphs, int);
+ Newz(0, paramFormats, imp_sth->numphs, int);
for (x=0,currph=imp_sth->ph; NULL != currph; currph=currph->nextph,x++) {
if (BYTEAOID==currph->bind_type->type_id) {
paramLengths[x] = currph->valuelen;
@@ -1660,7 +1660,7 @@
statement[execsize] = '\0';
/* Populate paramTypes */
- paramTypes = calloc(imp_sth->numphs, sizeof(*paramTypes));
+ Newz(0, paramTypes, imp_sth->numphs, Oid);
for (x=0,currph=imp_sth->ph; NULL != currph; currph=currph->nextph) {
paramTypes[x++] = currph->bind_type->type_id;
}
@@ -1830,7 +1830,7 @@
/* Set up the type_info array if we have not seen it yet */
if (NULL==imp_sth->type_info) {
- imp_sth->type_info = calloc(num_fields, sizeof(*imp_sth->type_info)); /* freed in dbd_st_destroy */
+ Newz(0, imp_sth->type_info, num_fields, sql_type_info_t**);
for (i = 0; i < num_fields; ++i) {
imp_sth->type_info[i] = pg_type_data(PQftype(imp_sth->result, i));
}