Bug 1555 - Memory leak and off by one error
: Memory leak and off by one error
Status: RESOLVED FIXED
: GridFTP
GASS
: 2.0
: PC All
: P2 major
: ---
Assigned To:
:
:
:
:
  Show dependency treegraph
 
Reported: 2004-02-13 16:40 by
Modified: 2005-12-02 15:04 (History)


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2004-02-13 16:40:40
This is a patch from David Smith at CERN. It has been tested as part of the 
VDT. It fixes two things in the GASS HTTP transfer code:

1) A memory leak
2) An off by one error 


--- bad/gass/transfer/source/library/globus_gass_transfer_http.c    Mon Jan  5 
20:48:11 2004
+++ fix/gass/transfer/source/library/globus_gass_transfer_http.c    Wed Jan 21 
19:29:05 2004
@@ -1966,6 +1966,9 @@
     globus_l_gass_transfer_http_lock();
     proto = (globus_gass_transfer_http_listener_proto_t *) arg;
 
+    if (proto->request->connected_subject != GLOBUS_NULL)
+        globus_free(proto->request->connected_subject);
+
     proto->request->connected_subject = globus_libc_strdup(identity);
 
     switch(proto->request->authorization_mode)
@@ -5485,7 +5488,7 @@
    }
    if(input[i] == CR)
    {
-       if(i + 2 > max_to_scan)
+       if(i + 2 >= max_to_scan)
        {
        /* not enough data */
        return GLOBUS_TRUE;

-alain
------- Comment #1 From 2004-02-25 16:13:53 -------
Can you provide more information about what would trigger these bugs? 
 
joe 
------- Comment #2 From 2004-02-27 19:08:00 -------
Joe,
David may provide the details, but I can already say the following.
Both problem were discovered by running the Condor-G "gahp_server"
under the "valgrind" memory leak finder.

1. The memory leak seems fairly evident to me: if the pointer is
   non-null, it should first be freed, before it gets re-assigned
   on the next line.

2. The "valgrind" memory access checker actually reported an access
   to the element just after the end of the array, so it can happen!

FYI, the "gahp_server" is a *long-lived* Globus program, of which
there is an instance for each user submitting jobs through Condor-G.
In EDG/LCG jobs are submitted via a central Resource Broker, which
then may have many instances running in parallel, so all those leaks
can add up to a huge number!  This has actually been observed, and
that is why David has spent a lot of time chasing all the memory and
file descriptor leaks in the "gahp_server".  So please give these
carefully tested patches a serious consideration.  Thanks!
------- Comment #3 From 2004-03-02 09:37:49 -------
I'm just trying to verify the case where the memory leak occurs. I'm not sure 
that the function should be called more than once per request---hence, I'm 
concerned this patch is masking some other bad behavior. 
 
joe 
------- Comment #4 From 2004-03-02 09:50:58 -------
Hi Joe,

I saw that the routine was being called twice per connection. Are you able to
reproduce that? If not, I will send some more information - I can get the two
locations from where it was called.

Thanks,
David
------- Comment #5 From 2004-03-02 10:38:30 -------
Hello,

OK, I have the two places to hand so here they are:

The first is:

globus_l_io_write_auth_token() in globus_io_securesocket.c (line 2634)
-> globus_l_io_securesocket_call_auth_callback()
    -> handle->securesocket_attr.auth_callback()
       [globus_l_gass_transfer_http_authorization_callback]

and then

globus_l_io_write_auth_token() in globus_io_securesocket.c (line 2649)
-> init_info->callback()
   [globus_l_io_secure_accept_callback() in " (line 3072)]
    -> handle->securesocket_attr.auth_callback()
       [globus_l_gass_transfer_http_authorization_callback]

(line numbers are from my copy of the source, so they may vary for you)

David
------- Comment #6 From 2004-03-02 13:03:06 -------
I'm unable to duplicate the leak with the current CVS trunk (where the IO 
implementation is quite different than 2.4). I've committed the other part of 
the patch to 3.2 branch and trunk. 
 
joe