Fix bug in port eviction code
authorLudovic Courtès <ludo@gnu.org>
Wed, 10 Sep 2008 22:06:55 +0000 (00:06 +0200)
committerLudovic Courtès <ludo@gnu.org>
Wed, 10 Sep 2008 22:06:55 +0000 (00:06 +0200)
* libguile/fports.c (scm_i_evict_port): Check whether PORT has a
  ptab entry associated with it.  It's unclear when this can happen.

libguile/fports.c

index bcb5a1e..293aa1b 100644 (file)
@@ -228,9 +228,15 @@ scm_i_evict_port (void *closure, SCM port)
 
   if (SCM_FPORTP (port))
     {
-      scm_t_fport *fp = SCM_FSTREAM (port);
+      scm_t_port *p;
+      scm_t_fport *fp;
+
+      /* XXX: In some cases, we can encounter a port with no associated ptab
+        entry.  */
+      p = SCM_PTAB_ENTRY (port);
+      fp = (p != NULL) ? (scm_t_fport *) p->stream : NULL;
 
-      if (fp->fdes == fd)
+      if ((fp != NULL) && (fp->fdes == fd))
        {
          fp->fdes = dup (fd);
          if (fp->fdes == -1)