Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita71daab

Browse files
committed
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 usePQconndefaults() and are not updated to free the returned array viathe new PQconninfoFree() function. But PQconndefaults() is probably notused very much, so this seems like a good compromise.
1 parent773e84f commita71daab

File tree

8 files changed

+234
-137
lines changed

8 files changed

+234
-137
lines changed

‎src/interfaces/libpgtcl/pgtclCmds.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.47 2000/02/27 07:44:22 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.48 2000/03/11 03:08:35 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -237,25 +237,32 @@ tcl_value(char *value)
237237
int
238238
Pg_conndefaults(ClientDatacData,Tcl_Interp*interp,intargc,char**argv)
239239
{
240+
PQconninfoOption*options=PQconndefaults();
240241
PQconninfoOption*option;
241242
Tcl_DStringresult;
242243
charibuf[32];
243244

244-
Tcl_DStringInit(&result);
245-
for (option=PQconndefaults();option->keyword!=NULL;option++)
245+
if (options)
246246
{
247-
char*val=option->val ?option->val :"";
247+
Tcl_DStringInit(&result);
248248

249-
sprintf(ibuf,"%d",option->dispsize);
250-
Tcl_DStringStartSublist(&result);
251-
Tcl_DStringAppendElement(&result,option->keyword);
252-
Tcl_DStringAppendElement(&result,option->label);
253-
Tcl_DStringAppendElement(&result,option->dispchar);
254-
Tcl_DStringAppendElement(&result,ibuf);
255-
Tcl_DStringAppendElement(&result,val);
256-
Tcl_DStringEndSublist(&result);
249+
for (option=options;option->keyword!=NULL;option++)
250+
{
251+
char*val=option->val ?option->val :"";
252+
253+
sprintf(ibuf,"%d",option->dispsize);
254+
Tcl_DStringStartSublist(&result);
255+
Tcl_DStringAppendElement(&result,option->keyword);
256+
Tcl_DStringAppendElement(&result,option->label);
257+
Tcl_DStringAppendElement(&result,option->dispchar);
258+
Tcl_DStringAppendElement(&result,ibuf);
259+
Tcl_DStringAppendElement(&result,val);
260+
Tcl_DStringEndSublist(&result);
261+
}
262+
Tcl_DStringResult(interp,&result);
263+
264+
PQconninfoFree(options);
257265
}
258-
Tcl_DStringResult(interp,&result);
259266

260267
returnTCL_OK;
261268
}

‎src/interfaces/libpq/fe-auth.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.37 2000/02/07 23:10:08 petere Exp $
13+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.38 2000/03/11 03:08:36 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -75,7 +75,7 @@ struct authsvc
7575
* allowed. Unauthenticated connections are disallowed unless there
7676
* isn't any authentication system.
7777
*/
78-
staticstructauthsvcauthsvcs[]= {
78+
staticconststructauthsvcauthsvcs[]= {
7979
#ifdefKRB4
8080
{"krb4",STARTUP_KRB4_MSG,1},
8181
{"kerberos",STARTUP_KRB4_MSG,1},
@@ -94,7 +94,7 @@ static struct authsvc authsvcs[] = {
9494
{"password",STARTUP_PASSWORD_MSG,0}
9595
};
9696

97-
staticintn_authsvcs=sizeof(authsvcs) /sizeof(structauthsvc);
97+
staticconstintn_authsvcs=sizeof(authsvcs) /sizeof(structauthsvc);
9898

9999
#ifdefKRB4
100100
/*----------------------------------------------------------------
@@ -549,7 +549,14 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
549549
*
550550
* Set/return the authentication service currently selected for use by the
551551
* frontend. (You can only use one in the frontend, obviously.)
552+
*
553+
* NB: This is not thread-safe if different threads try to select different
554+
* authentication services! It's OK for fe_getauthsvc to select the default,
555+
* since that will be the same for all threads, but direct application use
556+
* of fe_setauthsvc is not thread-safe. However, use of fe_setauthsvc is
557+
* deprecated anyway...
552558
*/
559+
553560
staticintpg_authsvc=-1;
554561

555562
void
@@ -558,7 +565,7 @@ fe_setauthsvc(const char *name, char *PQerrormsg)
558565
inti;
559566

560567
for (i=0;i<n_authsvcs;++i)
561-
if (!strcmp(name,authsvcs[i].name))
568+
if (strcmp(name,authsvcs[i].name)==0)
562569
{
563570
pg_authsvc=i;
564571
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp