Re: Commit 5653

From: Martin Sevior (msevior@seviorpc.ph.unimelb.edu.au)
Date: Thu Aug 28 2003 - 04:03:49 EDT

  • Next message: Martin Sevior: "commit: Insert a spans of rows and columns."

    On Thu, 2003-08-28 at 15:41, Robert Wilhelm wrote:
    > I committed a fix for 5653 (RTF file makes valgrind unhappy).
    >
    > This shows us the joy of C++ programming:
    >
    > We had this code:
    >
    > char *szWork, szLoc;
    > int iBase, iSize;
    > UT_String sNewProp;
    >
    > szWork = sNewProp.substr(iBase, iSize-iBase).c_str(); // line 1
    > szLoc = strstr(szWork,":"); // line 2
    >
    >
    > Now UT_String::substr() returns a new UT_String object,
    > which lives very short and will be detroyed at end of line 1.
    >
    > Therefore in line 2 we access already freed memory.
    >

    Nice catch. It would have taken me a while to get than one!

    Cheers

    Martin

    > Have fun,
    >
    > Robert
    >



    This archive was generated by hypermail 2.1.4 : Thu Aug 28 2003 - 03:13:35 EDT