httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Edward L. Abrams" <>
Subject Re: Newbie: Question
Date Sat, 24 Jun 2006 21:19:18 GMT
Thank you for your reply.  Unfortunately, my module is written in C, so 
I suspect the modperl list might not be as helpful.

Here is the skeleton of my upload code.  The function given is the 
content handler for this particular request.  There are no significant 
prior input filters, and no significant posterior output filters.  When 
I POST an upload, this content handler saves the files in the multipart 
POST, and returns a trivial response (not fully shown).  In my testing, 
it tends to leak memory proportional (but not equal) to the size of the 
total upload.

I initialize mod_apreq in the way offered in the documentation: by 
LoadModule'ing it, and expecting it to insert itself into the latest 
possible input filter position (which should not be difficult, since I 
have no other custom input filters).

I apologize for the length of this email.  Thank you for helping out!



// a content handler
static int do_post(request_rec *r)
 apreq_handle_t *handle;
 const apreq_module_t *module;
 apreq_param_t *filebody, *testfilebody;
 apr_bucket_brigade *bb;
 apr_bucket *b;
 char *loopfilename, *myip, *disk, *tmpfile, *newfilename, 
*extensionfilename, *lastdot;
 char *localorigfilename_raw, *localorigfilename, *nameindex = NULL;
 const char *buf = NULL;
 apr_file_t *f = NULL;
 unsigned int md_len, copies, filesize = 0, any_processed = 0;
 apr_size_t bytes;
 int i, lresult = 0;

 handle = (apreq_handle_t *)apreq_handle_apache2(r);
 apreq_read_limit_set(handle, READ_LIMIT);
 module = handle->module;

 localorigfilename_raw = (char *)apr_pcalloc(r->pool, 512);
 loopfilename = (char *)apr_pcalloc(r->pool, 16);

 for (i = 0; i < MAX_FILES_PROCESSED; i++)
   filesize = 0;
   sprintf(loopfilename, "%s%d", DEFAULT_FILE_PARAM_NAME, i);

   // i do typically test whether this mulitpart part is a file -- for 
the sake of this skeleton, that code is omitted
   filebody = module->body_get(handle, loopfilename);
   memcpy(localorigfilename_raw, (filebody->v).data, 
   bb = filebody->upload;

   tmpfile = create_temp_path(disk, (char *)localorigfilename);

   if (apr_file_open(&f, 
r->pool) != APR_SUCCESS)
      return HTTP_FORBIDDEN;

   // dump the values in this brigade:
   for (b = APR_BRIGADE_FIRST(bb);
        b != APR_BRIGADE_SENTINEL(bb);
        b = APR_BUCKET_NEXT(b))
   {         if (APR_BUCKET_IS_EOS(b))
        else if (apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ) == 
          // We have a bucket full of raw data
          apr_file_write(f, buf, &bytes);
          filesize += bytes;

   if (bb != NULL)
     // apr_brigade_cleanup(bb);
 } // for i in 0 to MAX_FILES_PROCESSED

 if (any_processed > 0)
   return OK;
     return HTTP_FORBIDDEN;


Philip M. Gollucci wrote:
> Edward L. Abrams wrote:
>> Hello,
>> I apologize for my brief intrusion on this list for a question that 
>> may or may not be within the boundaries of the list's purpose.  I 
>> have been using libapreq to do file uploads for some time.  Lately, 
>> I've noticed that I have memory leaks.  I don't know whether it's my 
>> newbie use of mostly-undocumented code, or the code itself (I favor 
>> the former!).
> This is generally for developement of libapreq itself, but sometimes 
> user questions are on topic.
> You might try modperl (at) perl (dot) apache (dot) org
>> If this is the wrong place to ask what I am doing wrong in my code, 
>> where is the right place to ask?  The modules@ list was unresponsive, 
>> and I could find no other close candidate.  If this is not the wrong 
>> place to ask, then let me know, and I'll show you something that I 
>> believe you will be able to help me correct very easily.
> Can you show some code ?

View raw message