stack trace points to uninit data in below routine

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tvnaidu
    Contributor
    • Oct 2009
    • 365

    stack trace points to uninit data in below routine

    I have memory leak issue, I found from stack trace that "sendto" points to uninitialised data in the below routine, does vsnprintf cause this error?


    syscall param socketcall.send to(msg) points to uninitialised bytes(s)
    at 0x43B731E: sendto (in /lib/libpthread-2.5.so)
    by 0x439A019: adpModuleDebug (in /pfrm/lib/libi386adaptos. so)

    Code:
    f (!pEntry || (pEntry->debugLevel & debugLevel))
            {
            int len;
            char buf[256];
    
            len = sprintf(buf, "%s:%d:", function, line);
            va_start (arg, pszFormat);
            vsnprintf (&buf[len], 255-len, pszFormat, arg);
            va_end (arg);
            printf ("%s", buf);
            }
    Last edited by RedSon; Jan 19 '10, 03:50 PM. Reason: Added code tags
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Look, its not very difficult to put your code inside of code tags. You've posted over 200 messages to this board, you should know by now.

    The code tag button is the little one that looks like a hash mark. USE IT!

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      I don't see anything in the code snippet that involves threads or sockets. Do you use threads or sockets elsewhere in your program?

      Notice that sprintf returns a negative value if it fails. As a general principle you should trap this error return before using the return value to index into the buffer. This is unlikely to be your problem.

      By the way, as a general principle it would have been better to use snprintf rather than sprintf. This is unlikely to be your problem. If you use snprintf then not only might the return value be negative, it might also be larger than the size of your buffer -- you should trap that condition too.

      Comment

      • tvnaidu
        Contributor
        • Oct 2009
        • 365

        #4
        sorry for that, it won't repeat again

        Comment

        • tvnaidu
          Contributor
          • Oct 2009
          • 365

          #5
          I compiled with -g option, basically there is one IOCTL call in the above code with compilation switch, whcih calls sendto call, I am adding that code below:

          [ctags]
          Code:
              UMI_REQ_INFO *  pUmiReq;
              unsigned int    reqBufSize;
          
          
           pUmiReq = (UMI_REQ_INFO *)pBuf;
                  pUmiReq->cmd    = cmd;
                  pUmiReq->srcId  = pSrcCtx->myId;
                  pUmiReq->reqOpt = reqOpt;
                  pUmiReq->reqId  = reqId;
                  pUmiReq->req    = 1;
          
                  if (sendto (pSrcCtx->sockFd, pUmiReq, reqBufSize,
                              0, (struct sockaddr *) &destId, sizeof(UMI_COMP_ID)) == -1)
                      {
          [/ctags]
          Last edited by RedSon; Jan 19 '10, 07:09 PM. Reason: Added code tags by using the little # button!

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            The code tags are [ code] and [/CODE]

            not "ctags". Use the little hash button it will add them in for you.

            Comment

            • tvnaidu
              Contributor
              • Oct 2009
              • 365

              #7
              thank you sir, I did long back, forgot

              Comment

              • tvnaidu
                Contributor
                • Oct 2009
                • 365

                #8
                I did memset pUmiReq to zero before filling stuff, but still it didn't fix "uninitiali sed data", any idea what is the issue with the above sendto call?. thanks.

                Comment

                Working...