Re: memory allocation under AIX 3.2
Posted in 1992
}Date: Tue, 1 Sep 92 18:35:28 +0100 }From: Manuel Monteiro <uunet!ssf.pt!mm> }Subject: memory allocation under AIX 3.2 }X-Informix-List-Id: <list.1423> } }I had the following problem when upgrading from AIX 3.1 to AIX 3.2. } }In a esql/c program, when you pushquote((char *)str, strlen(str)), }what is really pushed into the stack is the pointer to the string, not }the contents of the string (I didn't know that 'call by reference' was }supported :-). } }With AIX 3.2 when you 'free' a block, previously allocated using }'malloc', its contents are destroyed. With AIX 3.1 its contents were }left undisturbed. } }I have several ec functions similar to } }f(fgl_pcnt) } int fgl_pcnt; }{ } ...; } char *x = malloc(...); /* x size is not known in compile time */ } } ...; /* calculates x value */ } } /* RETURN x */ } pushquote(x, strlen(x)); } doretalloc(1); } free( x ); /* must free x space before returning */ } return(1); }} } }To be called from 4GL programs } } CALL f() RETURNING str } }The problem is that the pointer pushed into the stack now points to a }'destroyed' block, no longer containing the values I want. } }Does anyone out there knows how to solve this problem (without }rewriting all those functions :-(? }Is there a port to AIX 3.2 that really copies the strings to the stack? } }BTW: I'm running INFORMIX-4GL Version 4.10.UD2 on a IBM RISC 6000/530 I wasn't sure I believed this diagnosis, but you're quite correct -- I cheated and looked at the source, and all the 4.1 stack routines do is copy the pointer onto the stack. The obvious thing to point out is that it is only coincidence that the programs used to work at all; what if you had tried to assign two successive values to the same allocated space, as in: s = malloc(space); strcpy(s, "something"); pushquote(s, strlen(s)); strcpy(s, "other string"); pushquote(s, strlen(s)); free(s); return(2); I fear me that you are going to have modify your code. I will raise this as an issue within Informix. Yours, Jonathan Leffler (johnl@obelix.informix.com) #include <disclaimer.h>