summaryrefslogtreecommitdiff
path: root/src/interfaces/perl5
diff options
context:
space:
mode:
authorTom Lane2000-03-11 03:08:37 +0000
committerTom Lane2000-03-11 03:08:37 +0000
commita71daab4b465c4701489dd992005c65ca8604584 (patch)
tree02ac5d760dacf002cc2db8134f37a7b4e4870c26 /src/interfaces/perl5
parent773e84f52a57e3d1d2d4c98c6f49925b7c47b4ac (diff)
Change PQconndefaults() to return a malloc'd array, instead of a static
array. This allows processing of conninfo strings to be made thread-safe, at the cost of a small memory leak in applications that use PQconndefaults() and are not updated to free the returned array via the new PQconninfoFree() function. But PQconndefaults() is probably not used very much, so this seems like a good compromise.
Diffstat (limited to 'src/interfaces/perl5')
-rw-r--r--src/interfaces/perl5/Pg.xs32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/interfaces/perl5/Pg.xs b/src/interfaces/perl5/Pg.xs
index 2c884c9c033..cd8e5fe6818 100644
--- a/src/interfaces/perl5/Pg.xs
+++ b/src/interfaces/perl5/Pg.xs
@@ -1,6 +1,6 @@
/*-------------------------------------------------------
*
- * $Id: Pg.xs,v 1.13 1999/10/13 02:26:37 momjian Exp $ with patch for NULs
+ * $Id: Pg.xs,v 1.14 2000/03/11 03:08:37 tgl Exp $ with patch for NULs
*
* Copyright (c) 1997, 1998 Edmund Mergl
*
@@ -247,17 +247,18 @@ PQsetdb(pghost, pgport, pgoptions, pgtty, dbname)
HV *
PQconndefaults()
CODE:
- PQconninfoOption *infoOption;
+ PQconninfoOption *infoOptions;
RETVAL = newHV();
- if (infoOption = PQconndefaults()) {
- while (infoOption->keyword != NULL) {
- if (infoOption->val != NULL) {
- hv_store(RETVAL, infoOption->keyword, strlen(infoOption->keyword), newSVpv(infoOption->val, 0), 0);
+ if (infoOptions = PQconndefaults()) {
+ PQconninfoOption *option;
+ for (option = infoOptions; option->keyword != NULL; option++) {
+ if (option->val != NULL) {
+ hv_store(RETVAL, option->keyword, strlen(option->keyword), newSVpv(option->val, 0), 0);
} else {
- hv_store(RETVAL, infoOption->keyword, strlen(infoOption->keyword), newSVpv("", 0), 0);
+ hv_store(RETVAL, option->keyword, strlen(option->keyword), newSVpv("", 0), 0);
}
- infoOption++;
}
+ PQconninfoFree(infoOptions);
}
OUTPUT:
RETVAL
@@ -774,17 +775,18 @@ setdb(pghost, pgport, pgoptions, pgtty, dbname)
HV *
conndefaults()
CODE:
- PQconninfoOption *infoOption;
+ PQconninfoOption *infoOptions;
RETVAL = newHV();
- if (infoOption = PQconndefaults()) {
- while (infoOption->keyword != NULL) {
- if (infoOption->val != NULL) {
- hv_store(RETVAL, infoOption->keyword, strlen(infoOption->keyword), newSVpv(infoOption->val, 0), 0);
+ if (infoOptions = PQconndefaults()) {
+ PQconninfoOption *option;
+ for (option = infoOptions; option->keyword != NULL; option++) {
+ if (option->val != NULL) {
+ hv_store(RETVAL, option->keyword, strlen(option->keyword), newSVpv(option->val, 0), 0);
} else {
- hv_store(RETVAL, infoOption->keyword, strlen(infoOption->keyword), newSVpv("", 0), 0);
+ hv_store(RETVAL, option->keyword, strlen(option->keyword), newSVpv("", 0), 0);
}
- infoOption++;
}
+ PQconninfoFree(infoOptions);
}
OUTPUT:
RETVAL