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

Commitda72b90

Browse files
committed
Major code cleanup following the pg_password insertion...
...malloc/free -> palloc/pfree...fopen/fclose -> AllocateFile/FreeFile
1 parent405740a commitda72b90

File tree

12 files changed

+53
-51
lines changed

12 files changed

+53
-51
lines changed

‎src/backend/commands/user.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ extern void AlterUser(AlterUserStmt *stmt) {
176176
boolexists= false,
177177
n,
178178
inblock;
179-
intmax_id=-1;
180179

181180
if (!(inblock=IsTransactionBlock()))
182181
BeginTransactionBlock();

‎src/backend/libpq/auth.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.19 1997/12/04 00:26:50 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.20 1997/12/09 03:10:31 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -397,10 +397,10 @@ pg_krb5_recvauth(int sock,
397397
username,kusername);
398398
fputs(PQerrormsg,stderr);
399399
pqdebug("%s",PQerrormsg);
400-
free(kusername);
400+
pfree(kusername);
401401
return (STATUS_ERROR);
402402
}
403-
free(kusername);
403+
pfree(kusername);
404404
return (STATUS_OK);
405405
}
406406

‎src/backend/libpq/crypt.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
#include<crypt.h>
1717
#endif
1818

19-
#include<postgres.h>
20-
#include<libpq/crypt.h>
21-
#include<utils/nabstime.h>
19+
#include"postgres.h"
20+
#include"libpq/crypt.h"
21+
#include"utils/nabstime.h"
22+
#include"utils/palloc.h"
23+
#include"storage/fd.h"
2224

2325
char*crypt_getpwdfilename() {
2426

@@ -32,7 +34,7 @@ char* crypt_getpwdfilename() {
3234
elog(FATAL,"crypt.c: PGDATA is not defined");
3335
exit(-1);
3436
}
35-
filename= (char*)malloc(strlen(env)+strlen(CRYPT_PWD_FILE)+2);
37+
filename= (char*)palloc(strlen(env)+strlen(CRYPT_PWD_FILE)+2);
3638
sprintf(filename,"%s/%s",env,CRYPT_PWD_FILE);
3739
}
3840

@@ -47,7 +49,7 @@ FILE* crypt_openpwdfile() {
4749
char*filename;
4850

4951
filename=crypt_getpwdfilename();
50-
return (fopen(filename,"r"));
52+
return (AllocateFile(filename,"r"));
5153
}
5254

5355
/*-------------------------------------------------------------------------*/
@@ -66,7 +68,7 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate
6668
/* store a copy of user login to return
6769
*/
6870
count=strcspn(parse,"#");
69-
*login= (char*)malloc(count+1);
71+
*login= (char*)palloc(count+1);
7072
strncpy(*login,parse,count);
7173
(*login)[count]='\0';
7274
parse+= (count+1);
@@ -79,15 +81,15 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate
7981
/* store a copy of user password to return
8082
*/
8183
count=strcspn(parse,"#");
82-
*pwd= (char*)malloc(count+1);
84+
*pwd= (char*)palloc(count+1);
8385
strncpy(*pwd,parse,count);
8486
(*pwd)[count]='\0';
8587
parse+= (count+1);
8688

8789
/* store a copy of date login becomes invalid
8890
*/
8991
count=strcspn(parse,"#");
90-
*valdate= (char*)malloc(count+1);
92+
*valdate= (char*)palloc(count+1);
9193
strncpy(*valdate,parse,count);
9294
(*valdate)[count]='\0';
9395
parse+= (count+1);
@@ -112,15 +114,15 @@ void crypt_getloginfo(const char* user, char** passwd, char** valuntil) {
112114
while (!feof(datafile)) {
113115
crypt_parsepwdfile(datafile,&login,&pwd,&valdate);
114116
if (!strcmp(login,user)) {
115-
free((void*)login);
117+
pfree((void*)login);
116118
*passwd=pwd;
117119
*valuntil=valdate;
118120
fclose(datafile);
119121
return;
120122
}
121-
free((void*)login);
122-
free((void*)pwd);
123-
free((void*)valdate);
123+
pfree((void*)login);
124+
pfree((void*)pwd);
125+
pfree((void*)valdate);
124126
}
125127
fclose(datafile);
126128
}
@@ -135,13 +137,13 @@ MsgType crypt_salt(const char* user) {
135137
crypt_getloginfo(user,&passwd,&valuntil);
136138

137139
if (passwd==NULL||*passwd=='\0') {
138-
if (passwd)free((void*)passwd);
139-
if (valuntil)free((void*)valuntil);
140+
if (passwd)pfree((void*)passwd);
141+
if (valuntil)pfree((void*)valuntil);
140142
returnSTARTUP_UNSALT_MSG;
141143
}
142144

143-
free((void*)passwd);
144-
if (valuntil)free((void*)valuntil);
145+
pfree((void*)passwd);
146+
if (valuntil)pfree((void*)valuntil);
145147
returnSTARTUP_SALT_MSG;
146148
}
147149

@@ -159,8 +161,8 @@ int crypt_verify(Port* port, const char* user, const char* pgpass) {
159161
crypt_getloginfo(user,&passwd,&valuntil);
160162

161163
if (passwd==NULL||*passwd=='\0') {
162-
if (passwd)free((void*)passwd);
163-
if (valuntil)free((void*)valuntil);
164+
if (passwd)pfree((void*)passwd);
165+
if (valuntil)pfree((void*)valuntil);
164166
returnSTATUS_ERROR;
165167
}
166168

@@ -179,8 +181,8 @@ int crypt_verify(Port* port, const char* user, const char* pgpass) {
179181
retval=STATUS_OK;
180182
}
181183

182-
free((void*)passwd);
183-
if (valuntil)free((void*)valuntil);
184+
pfree((void*)passwd);
185+
if (valuntil)pfree((void*)valuntil);
184186

185187
returnretval;
186188
}

‎src/backend/libpq/hba.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.24 1997/11/10 05:15:52 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.25 1997/12/09 03:10:38 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -404,7 +404,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
404404

405405

406406
/* put together the full pathname to the old config file */
407-
old_conf_file= (char*)malloc((strlen(DataDir)+
407+
old_conf_file= (char*)palloc((strlen(DataDir)+
408408
strlen(OLD_CONF_FILE)+2)*sizeof(char));
409409
sprintf(old_conf_file,"%s/%s",DataDir,OLD_CONF_FILE);
410410

@@ -427,7 +427,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
427427
* read */
428428

429429
/* put together the full pathname to the config file */
430-
conf_file= (char*)malloc((strlen(DataDir)+
430+
conf_file= (char*)palloc((strlen(DataDir)+
431431
strlen(CONF_FILE)+2)*sizeof(char));
432432
sprintf(conf_file,"%s/%s",DataDir,CONF_FILE);
433433

@@ -452,9 +452,9 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
452452
usermap_name,find_password_entries);
453453
FreeFile(file);
454454
}
455-
free(conf_file);
455+
pfree(conf_file);
456456
}
457-
free(old_conf_file);
457+
pfree(old_conf_file);
458458
return;
459459
}
460460

@@ -799,7 +799,7 @@ verify_against_usermap(const char DataDir[],
799799
* read */
800800

801801
/* put together the full pathname to the map file */
802-
map_file= (char*)malloc((strlen(DataDir)+
802+
map_file= (char*)palloc((strlen(DataDir)+
803803
strlen(MAP_FILE)+2)*sizeof(char));
804804
sprintf(map_file,"%s/%s",DataDir,MAP_FILE);
805805

@@ -826,7 +826,7 @@ verify_against_usermap(const char DataDir[],
826826
checks_out_p);
827827
FreeFile(file);
828828
}
829-
free(map_file);
829+
pfree(map_file);
830830

831831

832832
}

‎src/backend/libpq/password.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ verify_password(char *user, char *password, Port *port,
5656
returnSTATUS_ERROR;
5757
}
5858

59-
pw_file_fullname= (char*)malloc(strlen(DataDir)+strlen(pw_file_name)+2);
59+
pw_file_fullname= (char*)palloc(strlen(DataDir)+strlen(pw_file_name)+2);
6060
strcpy(pw_file_fullname,DataDir);
6161
strcat(pw_file_fullname,"/");
6262
strcat(pw_file_fullname,pw_file_name);

‎src/backend/libpq/portal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.11 1997/11/10 05:15:54 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.12 1997/12/09 03:10:43 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -612,7 +612,7 @@ PQgetAttr(PortalBuffer *portal,
612612
if (tbp)
613613
{
614614
len=tbp->lengths[tuple_offset][field_number];
615-
result=malloc(len+1);
615+
result=palloc(len+1);
616616
memcpy(result,
617617
tbp->values[tuple_offset][field_number],
618618
len);

‎src/backend/libpq/portalbuf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.8 1997/10/25 01:09:23 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.9 1997/12/09 03:10:45 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -58,7 +58,7 @@
5858
PortalEntry**portals= (PortalEntry**)NULL;
5959
size_tportals_array_size=0;
6060

61-
/* portals array memory ismalloc'd instead of using MemoryContexts */
61+
/* portals array memory ispalloc'd instead of using MemoryContexts */
6262
/* since it will be used by both front and backend programs*/
6363
/*GlobalMemory portals_mmcxt = (GlobalMemory) NULL; */
6464

@@ -83,7 +83,7 @@ portals_realloc(size_t size)
8383
newp= (PortalEntry**)realloc(portals,
8484
portals_array_size*sizeof(PortalEntry*));
8585
else
86-
newp= (PortalEntry**)malloc(portals_array_size*sizeof(PortalEntry*));
86+
newp= (PortalEntry**)palloc(portals_array_size*sizeof(PortalEntry*));
8787

8888
if (newp)
8989
portals=newp;

‎src/backend/libpq/pqpacket.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.11 1997/11/17 16:18:07 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.12 1997/12/09 03:10:51 scrappy Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -253,7 +253,7 @@ StartupInfo2PacketBuf(StartupInfo* s)
253253
PacketBuf* res;
254254
char* tmp;
255255
256-
res = (PacketBuf*)malloc(sizeof(PacketBuf));
256+
res = (PacketBuf*)palloc(sizeof(PacketBuf));
257257
res->len = htonl(sizeof(PacketBuf));
258258
res->data[0] = '\0';
259259
@@ -285,7 +285,7 @@ PacketBuf2StartupInfo(PacketBuf* p)
285285
StartupInfo* res;
286286
char* tmp;
287287
288-
res = (StartupInfo*)malloc(sizeof(StartupInfo));
288+
res = (StartupInfo*)palloc(sizeof(StartupInfo));
289289
290290
res->database[0]='\0';
291291
res->user[0]='\0';

‎src/backend/parser/scan.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* A lexical scanner generated by flex */
22

33
/* Scanner skeleton version:
4-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.4 1997/11/30 23:05:39 thomas Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.5 1997/12/09 03:11:00 scrappy Exp $
55
*/
66

77
#defineFLEX_SCANNER
@@ -539,7 +539,7 @@ char *yytext;
539539
*
540540
*
541541
* IDENTIFICATION
542-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.4 1997/11/30 23:05:39 thomas Exp $
542+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.5 1997/12/09 03:11:00 scrappy Exp $
543543
*
544544
*-------------------------------------------------------------------------
545545
*/
@@ -1212,7 +1212,7 @@ YY_RULE_SETUP
12121212
inti;
12131213
ScanKeyword*keyword;
12141214

1215-
for(i=strlen(yytext);i >=0;i--)
1215+
for(i=0;yytext[i];i++)
12161216
if (isupper(yytext[i]))
12171217
yytext[i]=tolower(yytext[i]);
12181218

‎src/backend/postmaster/postmaster.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.64 1997/12/07 20:57:45 scrappy Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.65 1997/12/09 03:11:08 scrappy Exp $
1414
*
1515
* NOTES
1616
*
@@ -88,6 +88,7 @@
8888
#include"storage/proc.h"
8989
#include"utils/elog.h"
9090
#include"port-protos.h"/* For gethostname() */
91+
#include"storage/fd.h"
9192

9293
#if defined(DBX_VERSION)
9394
#defineFORK() (0)
@@ -228,7 +229,7 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
228229

229230
sprintf(path,"%s%cbase%ctemplate1%cpg_class",
230231
DataDir,SEP_CHAR,SEP_CHAR,SEP_CHAR);
231-
fp=fopen(path,"r");
232+
fp=AllocateFile(path,"r");
232233
if (fp==NULL)
233234
{
234235
fprintf(stderr,"%s does not find the database system. "
@@ -244,7 +245,7 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
244245

245246
/* reason ValidatePgVersion failed. NULL if didn't */
246247

247-
fclose(fp);
248+
FreeFile(fp);
248249

249250
ValidatePgVersion(DataDir,&reason);
250251
if (reason)

‎src/bin/initlocation/initlocation

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#
1313
#
1414
# IDENTIFICATION
15-
# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation,v 1.1 1997/11/07 06:21:38 thomas Exp $
15+
# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation,v 1.2 1997/12/09 03:11:16 scrappy Exp $
1616
#
1717
#-------------------------------------------------------------------------
1818

@@ -35,11 +35,11 @@ do
3535
shift
3636
done
3737

38-
if [!-z"$badparm" ];then
38+
if [-n"$badparm" ];then
3939
echo"$CMDNAME: Unrecognized parameter '$badparm'"
4040
fi
4141

42-
if [!-z"$usage" ];then
42+
if [-n"$usage" ];then
4343
echo"Usage:$CMDNAME [-u SUPERUSER] DATADIR"
4444
exit 1
4545
fi

‎src/include/catalog/pg_user.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_user.h,v 1.6 1997/12/04 00:27:54 scrappy Exp $
10+
* $Id: pg_user.h,v 1.7 1997/12/09 03:11:25 scrappy Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -65,7 +65,7 @@ typedef FormData_pg_user *Form_pg_user;
6565
*initial contents of pg_user
6666
* ----------------
6767
*/
68-
DATA(insertOID=0 (postgresPGUIDttttpostgres2116994400 ));
68+
DATA(insertOID=0 (postgresPGUIDtttt""2116994400 ));
6969

7070
BKI_BEGIN
7171
#ifdefALLOW_PG_GROUP

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp