You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@axis.apache.org by "Emanuel Norrbin (JIRA)" <ax...@ws.apache.org> on 2006/01/26 02:37:09 UTC

[jira] Created: (AXISCPP-922) Resource leak in AttachmentHelper::extract_Attachment

Resource leak in AttachmentHelper::extract_Attachment
-----------------------------------------------------

         Key: AXISCPP-922
         URL: http://issues.apache.org/jira/browse/AXISCPP-922
     Project: Axis-C++
        Type: Bug
  Components: Server - Deserialization  
    Versions:  1.6 Final    
 Environment: All platforms, this issue was found in nightly drop 24-Jan-2006 21:23 
    Reporter: Emanuel Norrbin


File: server\apache2\AttachmentHelper.cpp
Method: void AttachmentHelper::extract_Attachment(char *pBuffer)
Line: 88 - 89

This is a very easy bug to spot and fix:

            xsd__base64Binary*  base64_attachment = new xsd__base64Binary();
            base64_attachment = AxisUtils::decodeFromBase64Binary(attach);		

In Java this code would be fine but in C++ is is a resource leak,
the first new is not needed since decodeFromBase64Binary will allocate the xsd__base64Binary.
I suggest replacing the two lines with this one:

xsd__base64Binary*  base64_attachment = AxisUtils::decodeFromBase64Binary(attach);

/Emanuel


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (AXISCPP-922) Resource leak in AttachmentHelper::extract_Attachment

Posted by "Emanuel Norrbin (JIRA)" <ax...@ws.apache.org>.
    [ http://issues.apache.org/jira/browse/AXISCPP-922?page=comments#action_12364052 ] 

Emanuel Norrbin commented on AXISCPP-922:
-----------------------------------------

There is actually another leak just a few lines down for binary attachments.

Starting from line 93 in server\apache2\AttachmentHelper.cpp:

             char* binaryBody = new char[attachment.length() + 1];
             strcpy(binaryBody, attachment.c_str());
             pSoapAttachment->addBody(binaryBody);

A char[] is allocated on the first line but SoapAttachment ::addBody(char* pchBinaryBody)
does not take over the pointer, it allocates a new one and copies the argument.

So, either binaryBody should be deleted (using delete[]) or addBody should take a reference
to the pointer and make sure to delete it later. SInce addBody(xsd__base64Binary* objBody)
takes over the pointer maybe addBody(char* pchBinaryBody) should do so also for efficiency.

/Emanuel


> Resource leak in AttachmentHelper::extract_Attachment
> -----------------------------------------------------
>
>          Key: AXISCPP-922
>          URL: http://issues.apache.org/jira/browse/AXISCPP-922
>      Project: Axis-C++
>         Type: Bug
>   Components: Server - Deserialization
>     Versions:  1.6 Final
>  Environment: All platforms, this issue was found in nightly drop 24-Jan-2006 21:23 
>     Reporter: Emanuel Norrbin

>
> File: server\apache2\AttachmentHelper.cpp
> Method: void AttachmentHelper::extract_Attachment(char *pBuffer)
> Line: 88 - 89
> This is a very easy bug to spot and fix:
>             xsd__base64Binary*  base64_attachment = new xsd__base64Binary();
>             base64_attachment = AxisUtils::decodeFromBase64Binary(attach);		
> In Java this code would be fine but in C++ is is a resource leak,
> the first new is not needed since decodeFromBase64Binary will allocate the xsd__base64Binary.
> I suggest replacing the two lines with this one:
> xsd__base64Binary*  base64_attachment = AxisUtils::decodeFromBase64Binary(attach);
> /Emanuel

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (AXISCPP-922) Resource leak in AttachmentHelper::extract_Attachment

Posted by "Emanuel Norrbin (JIRA)" <ax...@ws.apache.org>.
    [ http://issues.apache.org/jira/browse/AXISCPP-922?page=comments#action_12364135 ] 

Emanuel Norrbin commented on AXISCPP-922:
-----------------------------------------

Just to clarify, this issue was found in an old CVS drop downloaded from the Axis C++ home page,
but the issue also exists in svn revision 372576. I suggest letting addBody take over the pointer since
binary attachments could be big.

/Emanuel


> Resource leak in AttachmentHelper::extract_Attachment
> -----------------------------------------------------
>
>          Key: AXISCPP-922
>          URL: http://issues.apache.org/jira/browse/AXISCPP-922
>      Project: Axis-C++
>         Type: Bug
>   Components: Server - Deserialization
>     Versions:  1.6 Final
>  Environment: All platforms, this issue was found in nightly drop 24-Jan-2006 21:23 
>     Reporter: Emanuel Norrbin

>
> File: server\apache2\AttachmentHelper.cpp
> Method: void AttachmentHelper::extract_Attachment(char *pBuffer)
> Line: 88 - 89
> This is a very easy bug to spot and fix:
>             xsd__base64Binary*  base64_attachment = new xsd__base64Binary();
>             base64_attachment = AxisUtils::decodeFromBase64Binary(attach);		
> In Java this code would be fine but in C++ is is a resource leak,
> the first new is not needed since decodeFromBase64Binary will allocate the xsd__base64Binary.
> I suggest replacing the two lines with this one:
> xsd__base64Binary*  base64_attachment = AxisUtils::decodeFromBase64Binary(attach);
> /Emanuel

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (AXISCPP-922) Resource leak in AttachmentHelper::extract_Attachment

Posted by "Henrik Nordberg (JIRA)" <ax...@ws.apache.org>.
    [ http://issues.apache.org/jira/browse/AXISCPP-922?page=comments#action_12364057 ] 

Henrik Nordberg commented on AXISCPP-922:
-----------------------------------------

Well, if addBody() doesn't delete its argument, then why not simply:

pSoapAttachment->addBody(attachment.c_str()); 

> Resource leak in AttachmentHelper::extract_Attachment
> -----------------------------------------------------
>
>          Key: AXISCPP-922
>          URL: http://issues.apache.org/jira/browse/AXISCPP-922
>      Project: Axis-C++
>         Type: Bug
>   Components: Server - Deserialization
>     Versions:  1.6 Final
>  Environment: All platforms, this issue was found in nightly drop 24-Jan-2006 21:23 
>     Reporter: Emanuel Norrbin

>
> File: server\apache2\AttachmentHelper.cpp
> Method: void AttachmentHelper::extract_Attachment(char *pBuffer)
> Line: 88 - 89
> This is a very easy bug to spot and fix:
>             xsd__base64Binary*  base64_attachment = new xsd__base64Binary();
>             base64_attachment = AxisUtils::decodeFromBase64Binary(attach);		
> In Java this code would be fine but in C++ is is a resource leak,
> the first new is not needed since decodeFromBase64Binary will allocate the xsd__base64Binary.
> I suggest replacing the two lines with this one:
> xsd__base64Binary*  base64_attachment = AxisUtils::decodeFromBase64Binary(attach);
> /Emanuel

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (AXISCPP-922) Resource leak in AttachmentHelper::extract_Attachment

Posted by "nadir amra (JIRA)" <ax...@ws.apache.org>.
     [ https://issues.apache.org/jira/browse/AXISCPP-922?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

nadir amra closed AXISCPP-922.
------------------------------

       Resolution: Fixed
    Fix Version/s: current (nightly)

> Resource leak in AttachmentHelper::extract_Attachment
> -----------------------------------------------------
>
>                 Key: AXISCPP-922
>                 URL: https://issues.apache.org/jira/browse/AXISCPP-922
>             Project: Axis-C++
>          Issue Type: Bug
>          Components: Server - Deserialization
>    Affects Versions:  1.6 Final
>         Environment: All platforms, this issue was found in nightly drop 24-Jan-2006 21:23 
>            Reporter: Emanuel Norrbin
>             Fix For: current (nightly)
>
>
> File: server\apache2\AttachmentHelper.cpp
> Method: void AttachmentHelper::extract_Attachment(char *pBuffer)
> Line: 88 - 89
> This is a very easy bug to spot and fix:
>             xsd__base64Binary*  base64_attachment = new xsd__base64Binary();
>             base64_attachment = AxisUtils::decodeFromBase64Binary(attach);		
> In Java this code would be fine but in C++ is is a resource leak,
> the first new is not needed since decodeFromBase64Binary will allocate the xsd__base64Binary.
> I suggest replacing the two lines with this one:
> xsd__base64Binary*  base64_attachment = AxisUtils::decodeFromBase64Binary(attach);
> /Emanuel

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-c-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-c-dev-help@ws.apache.org