fetchListFTP: implemented, but crippled
Dag-Erling Smorgrav
des at ofug.org
Sat May 24 04:19:46 PDT 2003
Tim Kientzle <kientzle at acm.org> writes:
> Easiest fix: move 'name' field to end (which
> permits variably-sizing it) and redefine API
> to return a linked-list
That would work.
> Better fix: redesign API to return one
> entry at a time. Then client code can manage
> storage as appropriate. With this approach,
> struct url_ent could remain unchanged.
You'd run into trouble if the caller tried to perform another
operation before reaching the end of the list.
> The current API makes fetchListFTP pretty much
> unusable for me; I'm not comfortable with that
> kind of memory usage. If there's any concensus
> about which fix is appropriate, I can start
> putting it together.
Have you tried contacting the author?
> + /* Use last whitespace-separated token as filename */
That won't work for symlinks.
> + if(url_index >= url_list_length) {
> + new_url_list_length = url_list_length * 2;
> + new_url_list = malloc(sizeof(struct url_ent)
> + * new_url_list_length);
> + fprintf(stderr,"fetchListFTP: malloc(%d)\n",
> + sizeof(struct url_ent)
> + * new_url_list_length);
> + memcpy(new_url_list, url_list,
> + sizeof(struct url_ent)*url_list_length);
> + memset(new_url_list+url_list_length,0,
> + sizeof(struct url_ent)
> + *(new_url_list_length - url_list_length));
> + free(url_list);
> + url_list = new_url_list;
> + url_list_length = new_url_list_length;
> + }
You know, we have realloc() for a reason...
DES
--
Dag-Erling Smorgrav - des at ofug.org
More information about the freebsd-hackers
mailing list