W3C home > Mailing lists > Public > www-lib@w3.org > April to June 2003

libwww: memory problems

From: Paul Accosta <paco@hungary.cc>
Date: Wed, 21 May 2003 18:18:21 +0200
Message-ID: <20030521161822.31202.qmail@web1.mailbox.hu>
To: www-lib@w3.org

I have a program that is continuously posting data and getting a
response. The problem is as the program continues to run it start eating
up memory and processor time. After a while my simple post functions
takes minutes to complete. Im new to libwww but I thougth I had picked
it up pretty good from the examples. Does anyone have any idea what this
could be? Ill post my function below if that helps.

char * large_post(char * auth, char * dst_str, char *key[10], char
*value[10], int numfields)
{
	HTChunk * chunk = NULL;
	HTRequest * POSTrequest = NULL;
    HTAnchor * dst = NULL;
	HTAssocList * formfields = NULL;
	char * cwd;
	char  data[64];
	int x=0;
	unsigned char *ct;
	char ci[512];
	char co[544];
	char * ddata=NULL;
	char *content;

	ct = (unsigned char *)malloc(sizeof(unsigned char)*32);
	memcpy(ct,"foo:foobar",13);			
	//-- SET SSL PROTO --//
	HTSSL_protMethod_set(HTSSL_V23);
    HTSSL_verifyDepth_set(2);
	//-- REGISTER SSL --//
    HTSSLhttps_init(NO);
	HTUU_encode(ct, strlen((char *)ct), ci);
	strcpy(co, "Basic ");
	strcat(co, ci);
	formfields = HTAssocList_new();
    HTProfile_newNoCacheClient("MY_CLIENT", "2.0");
	HTHost_setEventTimeout(100000);

    if (data && *data && dst_str && *dst_str) 
	{
		cwd = HTGetCurrentDirectoryURL();
		for(x=0;x<numfields;x++)
		{
			HTAssocList_addObject(formfields,key[x],value[x]);
		}
		POSTrequest = HTRequest_new();
		HTRequest_setOutputFormat(POSTrequest,WWW_SOURCE);
		HTRequest_addConnection(POSTrequest, "close", "");
		HTRequest_addCredentials(POSTrequest, "Authorization", co);
		dst = HTAnchor_findAddress(dst_str);
		chunk = HTPostFormAnchorToChunk(formfields,dst,POSTrequest);
		HT_FREE(cwd);

	if (chunk) {		
            HTEventList_loop(POSTrequest);
            ddata = HTChunk_toCString(chunk);
            content=ddata;
        
        }
     }
	HTAssocList_delete(formfields);
	HTRequest_delete(POSTrequest);
	HTSSLhttps_terminate();
	HTProfile_delete();

	free(ct);
	return ddata;
}

int terminate_handler (HTRequest * request, HTResponse * response, void
* param, int status)
{
	HTEventList_stopLoop();
	return 0;
}
Received on Wednesday, 21 May 2003 12:18:29 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 23 April 2007 18:18:43 GMT