7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.75 2001/04/03 02:31:52 tgl Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.76 2001/04/03 04:07:02 tgl Exp $
11
11
*
12
12
* NOTES:
13
13
*
@@ -484,7 +484,8 @@ AllocateVfd(void)
484
484
{
485
485
/* initialize header entry first time through */
486
486
VfdCache = (Vfd * ) malloc (sizeof (Vfd ));
487
- Assert (VfdCache != NULL );
487
+ if (VfdCache == NULL )
488
+ elog (FATAL , "AllocateVfd: no room for VFD array" );
488
489
MemSet ((char * ) & (VfdCache [0 ]), 0 , sizeof (Vfd ));
489
490
VfdCache -> fd = VFD_CLOSED ;
490
491
@@ -506,17 +507,23 @@ AllocateVfd(void)
506
507
* However, there's not much point in starting *real* small.
507
508
*/
508
509
Size newCacheSize = SizeVfdCache * 2 ;
510
+ Vfd * newVfdCache ;
509
511
510
512
if (newCacheSize < 32 )
511
513
newCacheSize = 32 ;
512
514
513
- VfdCache = (Vfd * ) realloc (VfdCache , sizeof (Vfd ) * newCacheSize );
514
- Assert (VfdCache != NULL );
515
+ /*
516
+ * Be careful not to clobber VfdCache ptr if realloc fails;
517
+ * we will need it during proc_exit cleanup!
518
+ */
519
+ newVfdCache = (Vfd * ) realloc (VfdCache , sizeof (Vfd ) * newCacheSize );
520
+ if (newVfdCache == NULL )
521
+ elog (FATAL , "AllocateVfd: no room to enlarge VFD array" );
522
+ VfdCache = newVfdCache ;
515
523
516
524
/*
517
525
* Initialize the new entries and link them into the free list.
518
526
*/
519
-
520
527
for (i = SizeVfdCache ; i < newCacheSize ; i ++ )
521
528
{
522
529
MemSet ((char * ) & (VfdCache [i ]), 0 , sizeof (Vfd ));
@@ -529,7 +536,6 @@ AllocateVfd(void)
529
536
/*
530
537
* Record the new size
531
538
*/
532
-
533
539
SizeVfdCache = newCacheSize ;
534
540
}
535
541
@@ -553,6 +559,7 @@ FreeVfd(File file)
553
559
free (vfdP -> fileName );
554
560
vfdP -> fileName = NULL ;
555
561
}
562
+ vfdP -> fdstate = 0x0 ;
556
563
557
564
vfdP -> nextFree = VfdCache [0 ].nextFree ;
558
565
VfdCache [0 ].nextFree = file ;
@@ -678,7 +685,9 @@ fileNameOpenFile(FileName fileName,
678
685
679
686
Insert (file );
680
687
681
- vfdP -> fileName = malloc (strlen (fileName ) + 1 );
688
+ vfdP -> fileName = (char * ) malloc (strlen (fileName ) + 1 );
689
+ if (vfdP -> fileName == NULL )
690
+ elog (FATAL , "fileNameOpenFile: no room to save VFD filename" );
682
691
strcpy (vfdP -> fileName , fileName );
683
692
684
693
/* Saved flags are adjusted to be OK for re-opening file */
0 commit comments