stupid talloc questions

Holger Hetterich hhetter at novell.com
Thu Sep 24 08:31:01 MDT 2009


Hi,

still I am not really used to talloc.

Therefore I would like to ask some questions, and in advance forgive me if this are
the most stupid questions you've ever seen on this list. The first three questions are
just for understanding and "to make sure" (I've read the talloc-guide but just want to
get this clean), the last is about talloc_tos().

The following code is untested, just written:

void *context;
char *a;
a = talloc (context, char *);
if ( a!= NULL) { /*do something */ }
talloc_free(context);

My understanding is that talloc gives me an "unlimited" number of memory under a context.
So freeing context should free a.

Is this correct?


Next:
        void *context;
        char *a;
        char *b;
        a = talloc (context, char *);
        b = talloc (context, char *);
        if ( a!=NULL && b!=NULL ) { /*do something */ }
        talloc_free(context);

If what is said above is true, in this case, a and b should be freed. Correct?

Next:
      void *context;
      char *a;
      char *b;
      char *c;
      a = talloc (context, char *);
      b = talloc (a, char *);
      c = talloc (b, char *);
      /* do something */
      talloc_free(b);

Is this possible? According to the docs, the returned value is itself a talloc context.
So freeing b should result in freeing b and c. Correct?

Next:

char *a;
a = talloc ( talloc_tos(), char *);
if ( a!=NULL) /* do something */

I suppose tos() means top-of-stack. When and how will this memory be freed?
Do I have to use talloc_free on this? And if so, with which context?

Thanks and sorry for the stupid questions.
Holger



--
Holger Hetterich, hhetter at novell.com, 
  SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg)
   Maxfeldstr. 5, 90409 Nürnberg, Germany



More information about the samba-technical mailing list