Re: chunk example crashing if iterated

At 20:47 5/30/98 -0400, Filippo Menczer wrote:
>Could someone help me figure out why this simple example is crashing?
>Basically I am calling the code in the "chunk" example multiple times
>by wrapping a loop around it. The first time it goes fine, the second
>causes a segmentation fault.

Try and move the profile stuff (which does all the initialization of libwww
outside your loop.

Henrik

*****

#include "WWWLib.h"
#include "WWWHTTP.h"
#include "WWWInit.h"

void mygetchunk(char *url)
{
    HTRequest *request = HTRequest_new();
    HTChunk *chunk = NULL;
    HTRequest_setOutputFormat(request, WWW_SOURCE);
    if (url) {
        char *cwd = HTGetCurrentDirectoryURL();
        char *absolute_url = HTParse(url, cwd, PARSE_ALL);
        chunk = HTLoadToChunk(absolute_url, request);
        HT_FREE(absolute_url);
        HT_FREE(cwd);
        printf("%s\n", chunk ? "OK-FIRST-TIME" : "NO DATA");
    }
    HTRequest_delete(request);
}

main()
{
    /* Start libwww */
    HTProfile_newPreemptiveClient("TestApp", "1.0");
    HTSetTraceMessageMask("sop");

    /* Do the gets */
    mygetchunk("http://www.cs.ucsd.edu/~fil/agents");
    mygetchunk("http://www.cs.ucsd.edu/~fil/agents"); /* any URL here */

    /* Close libwww down */
    HTProfile_delete();
}

--
Henrik Frystyk Nielsen,
World Wide Web Consortium
http://www.w3.org/People/Frystyk

Received on Monday, 1 June 1998 09:02:34 UTC