Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3529

Freed memory should not be used

    XMLWordPrintable

    Details

    • Message:
      Review this memory access; the memory has already been released.
    • Highlighting:
      • Primary: xxx
      • Secondary: free call
    • Default Severity:
      Blocker
    • Impact:
      High
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way, MISRA C++ 2008 recommended
    • Covered Languages:
      C, C++, Objective-C
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      20min
    • CERT:
      MEM30-C., EXP54-CPP., MEM50-CPP.
    • CWE:
      CWE-416

      Description

      Once a block of memory has been {{free}}d, it becomes available for other memory requests. Whether it's re-used immediately, some time later, or not at all is random, and may vary based on load. Because of that randomness, tests may pass when running locally, but the odds are that such code will fail spectacularly in production by returning strange values, executing unexpected code, or causing a program crash.

      Noncompliant Code Example

      char *cp = malloc(sizeof(char)*10);
      
      // ...
      free(cp);
      
      cp[9] = 0;  // Noncompliant
      

      See

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: