Major code cleanup following the pg_password insertion...

...malloc/free -> palloc/pfree
	...fopen/fclose -> AllocateFile/FreeFile
This commit is contained in:
Marc G. Fournier 1997-12-09 03:11:25 +00:00
parent 405740ace6
commit da72b903ff
12 changed files with 53 additions and 51 deletions

View File

@ -176,7 +176,6 @@ extern void AlterUser(AlterUserStmt *stmt) {
bool exists = false,
n,
inblock;
int max_id = -1;
if (!(inblock = IsTransactionBlock()))
BeginTransactionBlock();

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.19 1997/12/04 00:26:50 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.20 1997/12/09 03:10:31 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -397,10 +397,10 @@ pg_krb5_recvauth(int sock,
username, kusername);
fputs(PQerrormsg, stderr);
pqdebug("%s", PQerrormsg);
free(kusername);
pfree(kusername);
return (STATUS_ERROR);
}
free(kusername);
pfree(kusername);
return (STATUS_OK);
}

View File

@ -16,9 +16,11 @@
#include <crypt.h>
#endif
#include <postgres.h>
#include <libpq/crypt.h>
#include <utils/nabstime.h>
#include "postgres.h"
#include "libpq/crypt.h"
#include "utils/nabstime.h"
#include "utils/palloc.h"
#include "storage/fd.h"
char* crypt_getpwdfilename() {
@ -32,7 +34,7 @@ char* crypt_getpwdfilename() {
elog(FATAL, "crypt.c: PGDATA is not defined");
exit(-1);
}
filename = (char*)malloc(strlen(env) + strlen(CRYPT_PWD_FILE) + 2);
filename = (char*)palloc(strlen(env) + strlen(CRYPT_PWD_FILE) + 2);
sprintf(filename, "%s/%s", env, CRYPT_PWD_FILE);
}
@ -47,7 +49,7 @@ FILE* crypt_openpwdfile() {
char* filename;
filename = crypt_getpwdfilename();
return (fopen(filename, "r"));
return (AllocateFile(filename, "r"));
}
/*-------------------------------------------------------------------------*/
@ -66,7 +68,7 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate
/* store a copy of user login to return
*/
count = strcspn(parse, "#");
*login = (char*)malloc(count + 1);
*login = (char*)palloc(count + 1);
strncpy(*login, parse, count);
(*login)[count] = '\0';
parse += (count + 1);
@ -79,7 +81,7 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate
/* store a copy of user password to return
*/
count = strcspn(parse, "#");
*pwd = (char*)malloc(count + 1);
*pwd = (char*)palloc(count + 1);
strncpy(*pwd, parse, count);
(*pwd)[count] = '\0';
parse += (count + 1);
@ -87,7 +89,7 @@ void crypt_parsepwdfile(FILE* datafile, char** login, char** pwd, char** valdate
/* store a copy of date login becomes invalid
*/
count = strcspn(parse, "#");
*valdate = (char*)malloc(count + 1);
*valdate = (char*)palloc(count + 1);
strncpy(*valdate, parse, count);
(*valdate)[count] = '\0';
parse += (count + 1);
@ -112,15 +114,15 @@ void crypt_getloginfo(const char* user, char** passwd, char** valuntil) {
while (!feof(datafile)) {
crypt_parsepwdfile(datafile, &login, &pwd, &valdate);
if (!strcmp(login, user)) {
free((void*)login);
pfree((void*)login);
*passwd = pwd;
*valuntil = valdate;
fclose(datafile);
return;
}
free((void*)login);
free((void*)pwd);
free((void*)valdate);
pfree((void*)login);
pfree((void*)pwd);
pfree((void*)valdate);
}
fclose(datafile);
}
@ -135,13 +137,13 @@ MsgType crypt_salt(const char* user) {
crypt_getloginfo(user, &passwd, &valuntil);
if (passwd == NULL || *passwd == '\0') {
if (passwd) free((void*)passwd);
if (valuntil) free((void*)valuntil);
if (passwd) pfree((void*)passwd);
if (valuntil) pfree((void*)valuntil);
return STARTUP_UNSALT_MSG;
}
free((void*)passwd);
if (valuntil) free((void*)valuntil);
pfree((void*)passwd);
if (valuntil) pfree((void*)valuntil);
return STARTUP_SALT_MSG;
}
@ -159,8 +161,8 @@ int crypt_verify(Port* port, const char* user, const char* pgpass) {
crypt_getloginfo(user, &passwd, &valuntil);
if (passwd == NULL || *passwd == '\0') {
if (passwd) free((void*)passwd);
if (valuntil) free((void*)valuntil);
if (passwd) pfree((void*)passwd);
if (valuntil) pfree((void*)valuntil);
return STATUS_ERROR;
}
@ -179,8 +181,8 @@ int crypt_verify(Port* port, const char* user, const char* pgpass) {
retval = STATUS_OK;
}
free((void*)passwd);
if (valuntil) free((void*)valuntil);
pfree((void*)passwd);
if (valuntil) pfree((void*)valuntil);
return retval;
}

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.24 1997/11/10 05:15:52 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.25 1997/12/09 03:10:38 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -404,7 +404,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
/* put together the full pathname to the old config file */
old_conf_file = (char *) malloc((strlen(DataDir) +
old_conf_file = (char *) palloc((strlen(DataDir) +
strlen(OLD_CONF_FILE) + 2) * sizeof(char));
sprintf(old_conf_file, "%s/%s", DataDir, OLD_CONF_FILE);
@ -427,7 +427,7 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
* read */
/* put together the full pathname to the config file */
conf_file = (char *) malloc((strlen(DataDir) +
conf_file = (char *) palloc((strlen(DataDir) +
strlen(CONF_FILE) + 2) * sizeof(char));
sprintf(conf_file, "%s/%s", DataDir, CONF_FILE);
@ -452,9 +452,9 @@ find_hba_entry(const char DataDir[], const struct in_addr ip_addr,
usermap_name, find_password_entries);
FreeFile(file);
}
free(conf_file);
pfree(conf_file);
}
free(old_conf_file);
pfree(old_conf_file);
return;
}
@ -799,7 +799,7 @@ verify_against_usermap(const char DataDir[],
* read */
/* put together the full pathname to the map file */
map_file = (char *) malloc((strlen(DataDir) +
map_file = (char *) palloc((strlen(DataDir) +
strlen(MAP_FILE) + 2) * sizeof(char));
sprintf(map_file, "%s/%s", DataDir, MAP_FILE);
@ -826,7 +826,7 @@ verify_against_usermap(const char DataDir[],
checks_out_p);
FreeFile(file);
}
free(map_file);
pfree(map_file);
}

View File

@ -56,7 +56,7 @@ verify_password(char *user, char *password, Port *port,
return STATUS_ERROR;
}
pw_file_fullname = (char *) malloc(strlen(DataDir) + strlen(pw_file_name) + 2);
pw_file_fullname = (char *) palloc(strlen(DataDir) + strlen(pw_file_name) + 2);
strcpy(pw_file_fullname, DataDir);
strcat(pw_file_fullname, "/");
strcat(pw_file_fullname, pw_file_name);

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.11 1997/11/10 05:15:54 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portal.c,v 1.12 1997/12/09 03:10:43 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -612,7 +612,7 @@ PQgetAttr(PortalBuffer *portal,
if (tbp)
{
len = tbp->lengths[tuple_offset][field_number];
result = malloc(len + 1);
result = palloc(len + 1);
memcpy(result,
tbp->values[tuple_offset][field_number],
len);

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.8 1997/10/25 01:09:23 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/portalbuf.c,v 1.9 1997/12/09 03:10:45 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -58,7 +58,7 @@
PortalEntry **portals = (PortalEntry **) NULL;
size_t portals_array_size = 0;
/* portals array memory is malloc'd instead of using MemoryContexts */
/* portals array memory is palloc'd instead of using MemoryContexts */
/* since it will be used by both front and backend programs*/
/* GlobalMemory portals_mmcxt = (GlobalMemory) NULL; */
@ -83,7 +83,7 @@ portals_realloc(size_t size)
newp = (PortalEntry **) realloc(portals,
portals_array_size * sizeof(PortalEntry *));
else
newp = (PortalEntry **) malloc(portals_array_size * sizeof(PortalEntry *));
newp = (PortalEntry **) palloc(portals_array_size * sizeof(PortalEntry *));
if (newp)
portals = newp;

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.11 1997/11/17 16:18:07 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/Attic/pqpacket.c,v 1.12 1997/12/09 03:10:51 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -253,7 +253,7 @@ StartupInfo2PacketBuf(StartupInfo* s)
PacketBuf* res;
char* tmp;
res = (PacketBuf*)malloc(sizeof(PacketBuf));
res = (PacketBuf*)palloc(sizeof(PacketBuf));
res->len = htonl(sizeof(PacketBuf));
res->data[0] = '\0';
@ -285,7 +285,7 @@ PacketBuf2StartupInfo(PacketBuf* p)
StartupInfo* res;
char* tmp;
res = (StartupInfo*)malloc(sizeof(StartupInfo));
res = (StartupInfo*)palloc(sizeof(StartupInfo));
res->database[0]='\0';
res->user[0]='\0';

View File

@ -1,7 +1,7 @@
/* A lexical scanner generated by flex */
/* Scanner skeleton version:
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.4 1997/11/30 23:05:39 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.5 1997/12/09 03:11:00 scrappy Exp $
*/
#define FLEX_SCANNER
@ -539,7 +539,7 @@ char *yytext;
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.4 1997/11/30 23:05:39 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.5 1997/12/09 03:11:00 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -1212,7 +1212,7 @@ YY_RULE_SETUP
int i;
ScanKeyword *keyword;
for(i = strlen(yytext); i >= 0; i--)
for(i = 0; yytext[i]; i++)
if (isupper(yytext[i]))
yytext[i] = tolower(yytext[i]);

View File

@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.64 1997/12/07 20:57:45 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.65 1997/12/09 03:11:08 scrappy Exp $
*
* NOTES
*
@ -88,6 +88,7 @@
#include "storage/proc.h"
#include "utils/elog.h"
#include "port-protos.h" /* For gethostname() */
#include "storage/fd.h"
#if defined(DBX_VERSION)
#define FORK() (0)
@ -228,7 +229,7 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
sprintf(path, "%s%cbase%ctemplate1%cpg_class",
DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR);
fp = fopen(path, "r");
fp = AllocateFile(path, "r");
if (fp == NULL)
{
fprintf(stderr, "%s does not find the database system. "
@ -244,7 +245,7 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
/* reason ValidatePgVersion failed. NULL if didn't */
fclose(fp);
FreeFile(fp);
ValidatePgVersion(DataDir, &reason);
if (reason)

View File

@ -12,7 +12,7 @@
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation,v 1.1 1997/11/07 06:21:38 thomas Exp $
# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/initlocation,v 1.2 1997/12/09 03:11:16 scrappy Exp $
#
#-------------------------------------------------------------------------
@ -35,11 +35,11 @@ do
shift
done
if [ ! -z "$badparm" ]; then
if [ -n "$badparm" ]; then
echo "$CMDNAME: Unrecognized parameter '$badparm'"
fi
if [ ! -z "$usage" ]; then
if [ -n "$usage" ]; then
echo "Usage: $CMDNAME [-u SUPERUSER] DATADIR"
exit 1
fi

View File

@ -7,7 +7,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_user.h,v 1.6 1997/12/04 00:27:54 scrappy Exp $
* $Id: pg_user.h,v 1.7 1997/12/09 03:11:25 scrappy Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@ -65,7 +65,7 @@ typedef FormData_pg_user *Form_pg_user;
* initial contents of pg_user
* ----------------
*/
DATA(insert OID = 0 ( postgres PGUID t t t t postgres 2116994400 ));
DATA(insert OID = 0 ( postgres PGUID t t t t "" 2116994400 ));
BKI_BEGIN
#ifdef ALLOW_PG_GROUP