Return-Path: Delivered-To: apmail-ws-axis-c-dev-archive@www.apache.org Received: (qmail 22868 invoked from network); 16 Sep 2005 11:25:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 16 Sep 2005 11:25:02 -0000 Received: (qmail 49683 invoked by uid 500); 16 Sep 2005 11:24:58 -0000 Delivered-To: apmail-ws-axis-c-dev-archive@ws.apache.org Received: (qmail 49375 invoked by uid 500); 16 Sep 2005 11:24:56 -0000 Mailing-List: contact axis-c-dev-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: "Apache AXIS C Developers List" Reply-To: "Apache AXIS C Developers List" Delivered-To: mailing list axis-c-dev@ws.apache.org Received: (qmail 49349 invoked by uid 99); 16 Sep 2005 11:24:56 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=SPF_FAIL X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Sep 2005 04:24:55 -0700 Received: from ajax.apache.org (ajax.apache.org [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id BB1BF12F for ; Fri, 16 Sep 2005 13:24:54 +0200 (CEST) Message-ID: <2125440128.1126869894764.JavaMail.jira@ajax.apache.org> Date: Fri, 16 Sep 2005 13:24:54 +0200 (CEST) From: "Chinthana Danapala (JIRA)" To: axis-c-dev@ws.apache.org Subject: [jira] Resolved: (AXISCPP-825) delete/delete[] mismatch in XercesHandler.cpp In-Reply-To: <1781652119.1126575450416.JavaMail.jira@ajax.apache.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N [ http://issues.apache.org/jira/browse/AXISCPP-825?page=all ] Chinthana Danapala resolved AXISCPP-825: ---------------------------------------- Fix Version: current (nightly) Resolution: Fixed Applied the patch and tests are working fine with changes. > delete/delete[] mismatch in XercesHandler.cpp > --------------------------------------------- > > Key: AXISCPP-825 > URL: http://issues.apache.org/jira/browse/AXISCPP-825 > Project: Axis-C++ > Type: Bug > Components: Parser Library - Xerces > Versions: current (nightly) > Reporter: Henrik Nordberg > Assignee: Chinthana Danapala > Fix For: current (nightly) > > The function: > void XercesHandler::characters(const XMLCh* const chars, const unsigned int length) > has some memory management problems. The most obvious problem is that the memory allocated with new[] is deleted with delete (change the two delete statements to delete[] statements). But another problem is that the memory deleted sometimes was allocated by new[] and sometimes via Xerces' XMLString::transcode(). Currently XMLString::transcode() allocates memory using new[], but this may not always remain true. Calls to XMLString::transcode() should be matched by calls to XMLString::release(). > The quick fix is to change delete to delete[]. But in the long run it is better not to use pointers at all and just deal with std::strings (this is internal code). I think this will lead to fewer bugs and memory leaks and will not noticeably affect performance. > So the quick fix looks like this: > char* cp_CurrentNameOrValue = XMLString::transcode(chars); > char* cp_FullNameOrValue = new char[strlen(cp_PreviousNameOrValue) + strlen(cp_CurrentNameOrValue) + 1]; > strcpy(cp_FullNameOrValue, cp_PreviousNameOrValue); > strcat(cp_FullNameOrValue, cp_CurrentNameOrValue); > m_pNextElement->m_pchNameOrValue = (const char*)cp_FullNameOrValue; > delete[] (const_cast (cp_PreviousNameOrValue)); > delete[] cp_CurrentNameOrValue; > I also changed one strcat to strcpy to make the code more readable (and one line shorter). Another comment is that const casts can be dangerous and lead to confusing code. -- 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