Re: libtar: FTBFS on hurd-i386
On Tue, 2012-01-17 at 19:48 +0100, Samuel Thibault wrote:
> Svante Signell, le Tue 17 Jan 2012 19:24:40 +0100, a écrit :
> This is useless:
> > + bname[0] = '\0';
Removed!
> > @@ -135,25 +136,30 @@
> > if (ti == NULL)
> > return -1;
> > ti->ti_ino = s.st_ino;
> > - snprintf(ti->ti_name, sizeof(ti->ti_name), "%s",
> > - savename ? savename : realname);
> > + name = savename ? savename : realname;
> > + if ((ti->ti_name = malloc(strlen(name) + 1)) == NULL)
> > + return -1;
> > + snprintf(ti->ti_name, sizeof(ti->ti_name), "%s", name);
> > libtar_hash_add(td->td_h, ti);
> > + if (ti->ti_name != NULL)
> > + free(ti->ti_name);
>
> Don't free ti_name, it is needed above in the code, when
> libtar_hashptr_data() returns a ti value, and then th_set_link() called.
>
> You have to free it from the tar_close() function (which uses
> libtar_hash_free), by introducing a tar_ino_free function to replace the
> free parameter passed to libtar_hash_free.
This is a little tricky. Will be fixed next.
> > + i = readlink(realname, path, s.st_size);
> > if (i == -1)
>
> You need to free path here.
Done!
> > char *
> > th_get_pathname(TAR *t)
...
> Same story as dirname/basename, you have to free the previous pointer
> held by filename.
Done!
> > + if ((lnp->ln_save = malloc(len + 1)) == NULL)
> > + if ((lnp->ln_real = malloc(len + 1)) == NULL)
>
> You also need to care about when to free these.
Will have to look closer into this one too!
> > int
> > path_hashfunc(char *key, int numbuckets)
> > {
> > - char buf[MAXPATHLEN];
> > + char *buf, *buf_ptr;
> > char *p;
> > + int i;
> >
> > - strcpy(buf, key);
> > + buf = strdup(key);
> > p = basename(buf);
> > -
> > - return (((unsigned int)p[0]) % numbuckets);
> > + i = ((unsigned int)p[0]) % numbuckets;
> > + free(buf_ptr);
>
> buf_ptr was never assigned, I guess you meant buf.
This code (including buf_ptr=buf) was first meant for a basename
modifying its argument, but now we use the compat functions which don't.
Reply to: