TLI Programming, t_free() problem 386/ix

Marco S Hyman marc at dumbcat.sf.ca.us
Mon May 20 13:59:11 AEST 1991


In article <142 at icxn.UUCP> kjd at icxn.UUCP (Kevin J. Dunlap) writes:
 > I am having a problem with memory and using AT&T's TLI running on
 > Interactive 386/ix System V 3.2.2.  I have the updates to TCP/IP
 > installed (SSU.4a).

I see your problem.  Look at the man page for t_alloc again. I quote:

   "This function will allocate memory for the specified structure, and
   will also allocate memory for buffers referenced by the structure."

Your t_alloc call

  if ((unitdata =(struct t_unitdata *)t_alloc(fd,T_UNITDATA,T_ALL))==NULL) {

allocates both the t_unitdata structure but also all (T_ALL) fields in the
structure.  The maxlen field will be initialized for each buffer.  Later when
you do

  unitdata->opt.len = 0;
  unitdata->opt.buf = (char *)NULL;

  unitdata->udata.len = sizeof(*data);
  unitdata->udata.buf = (char *)data;

You overwrite the pointers that t_alloc built.  That memory is lost forever.
t_open and t_getinfo will give you the various lengths.   If you want to set
your own lengths use T_ADDR instead of T_ALL in the t_alloc call.  That's all
you wanted to allocate in your example.

// marc
-- 
// home: marc at dumbcat.sf.ca.us		pacbell!dumbcat!marc
// work: marc at ascend.com		uunet!aria!marc



More information about the Comp.unix.sysv386 mailing list