PVS-StudioWarnings

PVS-Studio warning V611 for libstagefright

Nov 10th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. AString StringPrintf(const char *format, ...) {
  2.   va_list ap;
  3.   va_start(ap, format);
  4.  
  5.   char *buffer;
  6. #ifdef _MSC_VER
  7.   int n = vsnprintf(NULL, 0, format, ap);
  8.   buffer = new char[n+1];                    <<<<====
  9.   vsnprintf(buffer, n+1, format, ap);
  10. #else
  11.   vasprintf(&buffer, format, ap);
  12. #endif
  13.   va_end(ap);
  14.  
  15.   AString result(buffer);
  16.  
  17.   free(buffer);                              <<<<====
  18.   buffer = NULL;
  19.  
  20.   return result;
  21. }
  22.  
  23. This suspicious code was found in libstagefright project by PVS-Studio static code analyzer.
  24. Warning message is:
  25. V611 The memory was allocated using 'new' operator but was released using the 'free' function. Consider inspecting operation logics behind the 'buffer' variable. astring.cpp 340
  26.  
  27. PVS-Studio is a static analyzer for detecting bugs in the source code of applications written in C, C++, C++11, C++/CX. Site: http://www.viva64.com/en/pvs-studio/
Advertisement
Add Comment
Please, Sign In to add comment