[271] in Hesiod
Re: to free or not to free
daemon@ATHENA.MIT.EDU (Todd C. Miller)
Tue May 23 13:27:55 1995
To: hesiod@MIT.EDU
In-Reply-To: Your message of "Tue, 23 May 1995 10:58:54 MDT."
Date: Tue, 23 May 1995 11:24:14 -0600
From: "Todd C. Miller" <Todd.Miller@cs.colorado.edu>
Here are the missing diffs from my last message. Argh.
- todd
*** programmer.txt.DIST Mon Oct 18 13:21:25 1993
--- programmer.txt Tue May 23 10:42:08 1995
***************
*** 65,76 ****
primary interface into the Hesiod name server. It takes two string
arguments, the name to be resolved, known as the HesiodName, and a type
indicating the type of service associated with this name, known as the
! HesiodNameType. hes_resolve() returns a pointer to an allocated array
of strings, a la argv[], containing all the data which matched the
query, one match per array slot. The array is NULL terminated. It is
! the responsibility of the caller to free the strings pointed to by
! this array and the array itself once the application is done with it.
! Successive calls to hes_resolve() will allocate new return vectors.
Note that a call to hes_resolve() may return more than one match. The
semantics of using or choosing between multiple matches is dependent
--- 65,76 ----
primary interface into the Hesiod name server. It takes two string
arguments, the name to be resolved, known as the HesiodName, and a type
indicating the type of service associated with this name, known as the
! HesiodNameType. hes_resolve() returns a pointer to a static array
of strings, a la argv[], containing all the data which matched the
query, one match per array slot. The array is NULL terminated. It is
! the responsibility of the caller to copy wanted data to its own space
! since successive calls to hes_resolve() will overwrite the static
! array.
Note that a call to hes_resolve() may return more than one match. The
semantics of using or choosing between multiple matches is dependent
***************
*** 99,105 ****
#include <hesiod.h>
char *HesiodName, *HesiodNameType;
! char **hp, *p;
hp = hes_resolve(HesiodName, HesiodNameType);
if (hp == NULL) {
--- 99,105 ----
#include <hesiod.h>
char *HesiodName, *HesiodNameType;
! char **hp, *p, *q;
hp = hes_resolve(HesiodName, HesiodNameType);
if (hp == NULL) {
***************
*** 112,121 ****
} else {
/* do your thing with hp */
for (p = *hp; p; p++) {
! process(p);
! free(p);
}
- free(hp);
}
--- 112,120 ----
} else {
/* do your thing with hp */
for (p = *hp; p; p++) {
! q = strdup(p);
! process(q);
}
}