Subject: memory error while using portals

From: <[email-masked]>
Date: Fri, 22 Apr 94 21:49:40 CDT

postgresers,

I defined a simple C function using PQlib which checks whether
an object with a given oid exists. I call this function within a 
transaction from other PQlib-based programs and it's been workin ok.
However, one program is giving me trouble exactly when this
simple function is called. The error I get is:

signal SEGV (no mapping at the fault address) in pbuf_freeTuples at 0x9a90
pbuf_freeTuples+0x50:   ld      [%i3], %o3

and a stack trace gives:

(dbxtool) where
pbuf_freeTuples() at 0x9a90
pbuf_freeGroup() at 0x9b40
pbuf_freePortal() at 0x9b6c
pbuf_setup() at 0x9c2c
dump_data() at 0xadc8
process_portal() at 0x5744
PQexec() at 0x657c
OM_ObjectExists(id = 42272), line 41 in "OM/src/OM_ObjectExists.c"

Within the caller program, the OM_ObjectExists function is repeatedly called
with different oid and works well until this happens (5th time).
Has anyone had any similar problem or can suggest a reason for this?
I am including the C function below.

Thanks for any help,

-Alfredo Sanchez
[email-masked]

-----------------------------
int OM_ObjectExists(id)

   unsigned long id;		/* ID OF OBJECT	TO LOOK FOR*/
{

   char postquery[512];		/* STORES QUERIES SUBMITTED TO POSTGRES */
   PortalBuffer *portalbuff;	/* POINTS TO DATA RETRIEVED FROM DB */
   char *result;		/* STORES RESULTS FROM PG OPERATIONS	*/
   int exists;			/* USED TO STORE THE FUNCTION'S RESULT */

   /* CHECK WHETHER OBJECT EXISTS */
   sprintf(postquery, "retrieve portal p1 (Objects.oid) \
                       where Objects.id = \"%ld\"",id);
   result = PQexec(postquery);
   if (result[0] != 'C') {
      HRLTdiag_Emit (HRLTdiag_Fatal, "Can't access Objects\n");
      return(PG_FAILED);
   }
   result = PQexec("fetch all in p1");
   if (result[0] != 'P') {
      HRLTdiag_Emit (HRLTdiag_Fatal, "Can't check whther Object exists\n");
      return(PG_FAILED);
   }
   portalbuff = PQparray("p1");
   if (PQntuples(portalbuff) == 0) 
      exists = FALSE;
   else
      exists = TRUE;
   /* CLOSE PORTAL */
   result = PQexec("close p1"); 
   if (result[0] != 'C') {  
      HRLTdiag_Emit (HRLTdiag_Fatal, "Can't close portal p1\n"); 
      return(PG_FAILED); 
   }
   return(exists);
}