🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.utils.bug
Article #250

gdbm-1.5 patch (repost)

#250
From: Phil Male
Date: Mon, 10 Aug 1992 22:49
174 lines
5850 bytes
Several people have mailed asking for this, so I thought it was worth
re-posting it. Its some fixes to gdbm-1.5. Some memory leaks are plugged and
the reorganise bugs are fixed.

Reorganise now returns the same file descriptor, and dosn't corrupt the
bucket cache when it completes the reorganise.


*** gdbmreorg.c.old	Thu Apr  9 00:02:04 1992
--- gdbmreorg.c	Thu Apr  9 00:10:30 1992
***************
*** 24,29 ****
--- 24,32 ----
                  Western Washington University
                  Bellingham, WA 98226
          phone:  (206) 676-3035
+ 
+     Cache and walking file descriptor patch applied
+ 	e-mail: phil@compnews.co.uk
         
  ************************************************************************/
  
***************
*** 74,79 ****
--- 77,83 ----
    gdbm_file_info *new_dbf;		/* The new file. */
    char *new_name;			/* A temporary name. */
    int  len;				/* Used in new_name construction. */
+   int new_desc;				/* Used to avoid walking file desc */
    datum key, nextkey, data;		/* For the sequential sweep. */
    struct stat fileinfo;			/* Information about the file. */
    int  index;				/* Use in moving the bucket cache. */
***************
*** 112,118 ****
    if (new_dbf == NULL)
      {
        gdbm_errno = GDBM_REORGANIZE_FAILED;
!       free (new_name);
        return -1;
      }
  
--- 116,122 ----
    if (new_dbf == NULL)
      {
        gdbm_errno = GDBM_REORGANIZE_FAILED;
!       free (new_name);	/* free up the space allocated to new_name */
        return -1;
      }
  
***************
*** 131,138 ****
  	      gdbm_close (new_dbf);
  	      gdbm_errno = GDBM_REORGANIZE_FAILED;
  	      unlink (new_name);
  	      return -1;
! 	    };
   	}
        else
   	{
--- 135,143 ----
  	      gdbm_close (new_dbf);
  	      gdbm_errno = GDBM_REORGANIZE_FAILED;
  	      unlink (new_name);
+ 	      free(new_name);	/* free up the space allocated to new_name */
  	      return -1;
! 	    }
   	}
        else
   	{
***************
*** 140,145 ****
--- 145,151 ----
  	  gdbm_close (new_dbf);
  	  gdbm_errno = GDBM_REORGANIZE_FAILED;
  	  unlink (new_name);
+ 	  free(new_name);	/* free up the space allocated to new_name */
  	  return -1;
   	}
        nextkey = gdbm_nextkey (dbf, key);
***************
*** 153,164 ****
      {
        gdbm_errno = GDBM_REORGANIZE_FAILED;
        gdbm_close (new_dbf);
        return -1;
      }
  
    /* Fix up DBF to have the correct information for the new file. */
    UNLOCK_FILE(dbf);
!   close (dbf->desc);
    free (dbf->header);
    free (dbf->dir);
    for (index = 0; index < CACHE_SIZE; index++)
--- 159,183 ----
      {
        gdbm_errno = GDBM_REORGANIZE_FAILED;
        gdbm_close (new_dbf);
+       unlink (new_name);
+       free(new_name);		/* free up the space allocated to new_name */
        return -1;
      }
  
    /* Fix up DBF to have the correct information for the new file. */
    UNLOCK_FILE(dbf);
!   /* phil - don't close the descriptor, dup it... */
!   /* close (dbf->desc); */
!   if ((new_desc = dup2(new_dbf->desc, dbf->desc)) < 0)
!     {
!       gdbm_close(new_dbf);
!       gdbm_errno = GDBM_REORGANIZE_FAILED;
!       unlink (new_name); /* unlink the created file */
!       free(new_name);		/* free up the space allocated to new_name */
!       return -1;
!     }
!   /* ...and reassign */
!   dbf->desc = new_desc;
    free (dbf->header);
    free (dbf->dir);
    for (index = 0; index < CACHE_SIZE; index++)
***************
*** 169,180 ****
  	free (dbf->bucket_cache[index].ca_data.dptr);
      }
  
!   dbf->desc           = new_dbf->desc;
    dbf->header         = new_dbf->header;
    dbf->dir            = new_dbf->dir;
    dbf->bucket         = new_dbf->bucket;
    dbf->bucket_dir     = new_dbf->bucket_dir;
!   dbf->cache_entry    = new_dbf->cache_entry;
    dbf->last_read      = new_dbf->last_read;
    for (index = 0; index < CACHE_SIZE; index++)
      dbf->bucket_cache[index] = new_dbf->bucket_cache[index];
--- 188,202 ----
  	free (dbf->bucket_cache[index].ca_data.dptr);
      }
  
!   /* dbf->desc           = new_dbf->desc; - now dup */
    dbf->header         = new_dbf->header;
    dbf->dir            = new_dbf->dir;
    dbf->bucket         = new_dbf->bucket;
    dbf->bucket_dir     = new_dbf->bucket_dir;
!   /* phil - do not assign the cache, it will/may be different... */
!   /* dbf->cache_entry    = new_dbf->cache_entry; */
!   /* use the new cache */
!   dbf->cache_entry    = &dbf->bucket_cache[new_dbf->last_read];
    dbf->last_read      = new_dbf->last_read;
    for (index = 0; index < CACHE_SIZE; index++)
      dbf->bucket_cache[index] = new_dbf->bucket_cache[index];
***************
*** 187,192 ****
--- 209,216 ----
  
    /* Make sure the new database is all on disk. */
    fsync (dbf->desc);
+ 
+   free(new_name);		/* free up space allocated to new name */
  
    return 0;
  }

-- 

phil 

 ------------------------------------------------------------------------------
   ___/   /
   /_/)  /    Phil Male, Director, Information Systems Engineering Group
  / /_ '/  Computer Newspaper Services, The Bishops Manor, Howden, DN14 7BL
 / / ///
 ------------------------------------------------------------------------------

Blessed are they who Go Around in Circles, for they Shall be Known
as Wheels.
Technical Details
Message-ID: <21139.9208102149@yoda.isdev.compnews.co.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!uk.co.COMpnews.yoda!phil

Show Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!uk.co.COMpnews.yoda!phil
From: phil@uk.co.COMpnews.yoda (Phil Male)
Subject: gdbm-1.5 patch (repost)
Message-ID: <21139.9208102149@yoda.isdev.compnews.co.uk>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Mon, 10 Aug 1992 22:49:56 GMT
Approved: bug-gnu-utils@prep.ai.mit.edu
Lines: 175