Examples of errors detected by the V701 diagnostic.


V701. realloc() possible leak: when realloc() fails in allocating memory, original pointer is lost. Consider assigning realloc() to a temporary pointer.


K Desktop Environment

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'lexBuf.strs' is lost. Consider assigning realloc() to a temporary pointer. vcc.y 638


static void lexAppendc(int c)
{
  lexBuf.strs = (char *) realloc(lexBuf.strs, (size_t) .... + 1);
  lexBuf.strs[lexBuf.strsLen] = c;
  ....
}

Similar errors can be found in some other places:

  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'mods' is lost. Consider assigning realloc() to a temporary pointer. ldapoperation.cpp 534
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'mods[i]->mod_vals.modv_bvals' is lost. Consider assigning realloc() to a temporary pointer. ldapoperation.cpp 579
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'ctrls' is lost. Consider assigning realloc() to a temporary pointer. ldapoperation.cpp 624
  • And 11 additional diagnostic messages.

Spring Engine

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'dest' is lost. Consider assigning realloc() to a temporary pointer. assimp blenderloader.cpp 217


void BlenderImporter::InternReadFile( const std::string& pFile,
  aiScene* pScene, IOSystem* pIOHandler)
{
  ....
  dest = reinterpret_cast<Bytef*>( realloc(dest,total) );
  memcpy(dest + total - have,block,have);
  ....
}

Similar errors can be found in some other places:

  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'dest' is lost. Consider assigning realloc() to a temporary pointer. assimp xglloader.cpp 181

LibreOffice

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'mpChunk' is lost. Consider assigning realloc() to a temporary pointer. fastattribs.cxx 88


void FastAttributeList::add(sal_Int32 nToken,
  const sal_Char* pValue, size_t nValueLength )
{
  maAttributeTokens.push_back( nToken );
  sal_Int32 nWritePosition = maAttributeValues.back();
  maAttributeValues.push_back( maAttributeValues.back() +
                               nValueLength + 1 );
  if (maAttributeValues.back() > mnChunkLength)
  {
     mnChunkLength = maAttributeValues.back();
     mpChunk = (sal_Char *) realloc( mpChunk, mnChunkLength );
  }
  strncpy(mpChunk + nWritePosition, pValue, nValueLength);
  mpChunk[nWritePosition + nValueLength] = '\0';
}

Similar errors can be found in some other places:

  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'ip->i_list' is lost. Consider assigning realloc() to a temporary pointer. include.c 325
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'trp->bp' is lost. Consider assigning realloc() to a temporary pointer. _tokens.c 219
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'pInfoBuffer' is lost. Consider assigning realloc() to a temporary pointer. security.c 323
  • And 5 additional diagnostic messages.

Git

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'str' is lost. Consider assigning realloc() to a temporary pointer. syslog.c 46


void syslog(....)
{
  char *str;
  int str_len;
  ....
  str = realloc(str, ++str_len + 1);
  if (!str)
  {
    warning("realloc failed: '%s'", strerror(errno));
    return;
  }
  ....
}

Doxygen

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'd' is lost. Consider assigning realloc() to a temporary pointer. qcstring.h 396


class BufStr
{
public:
  ....
  void resize(uint newlen)
  {
    ....
    m_buf = (char *)realloc(m_buf,m_size);
    ....
  }
private:
  uint m_size;
  char *m_buf;
  ....
}

Similar errors can be found in some other places:

  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'd' is lost. Consider assigning realloc() to a temporary pointer. qcstring.h 396
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'str' is lost. Consider assigning realloc() to a temporary pointer. growbuf.h 16
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'str' is lost. Consider assigning realloc() to a temporary pointer. growbuf.h 23
  • And 5 additional diagnostic messages.

FreeSWITCH

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'abuf' is lost. Consider assigning realloc() to a temporary pointer. switch_ivr_play_say.c 1535


SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(....)
{
  ....
  if (buflen > write_frame.buflen) {
    abuf = realloc(abuf, buflen);
    write_frame.data = abuf;
    write_frame.buflen = buflen;
  }
  ....
}

Similar errors can be found in some other places:

  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'buf' is lost. Consider assigning realloc() to a temporary pointer. switch_event.c 1556
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'buf' is lost. Consider assigning realloc() to a temporary pointer. switch_event.c 1582

Dolphin Smalltalk 7

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'elems' is lost. Consider assigning realloc() to a temporary pointer. compiler.cpp 2922


POTE Compiler::ParseByteArray()
{
  NextToken();
  while (m_ok && !ThisTokenIsClosing())
  {
    if (elemcount>=maxelemcount)
    {
      _ASSERTE(maxelemcount > 0);
      maxelemcount *= 2;
      elems = (BYTE*)realloc(elems, maxelemcount*sizeof(BYTE));
    }
    ....
  }
  ....
}

Similar errors can be found in some other places:

  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'm_pAllocations' is lost. Consider assigning realloc() to a temporary pointer. alloc.cpp 436
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'pUnmarked' is lost. Consider assigning realloc() to a temporary pointer. gc.cpp 217

Firebird

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 's->base' is lost. Consider assigning realloc() to a temporary pointer. mstring.c 42


int mputchar(struct mstring *s, int ch)
{
  if (!s || !s->base) return ch;
  if (s->ptr == s->end) {
    int len = s->end - s->base;
    if ((s->base = realloc(s->base, len+len+TAIL))) {
      s->ptr = s->base + len;
      s->end = s->base + len+len+TAIL; }
    else {
      s->ptr = s->end = 0;
      return ch; } }
  *s->ptr++ = ch;
  return ch;
}

Ruby MRI

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'table' is lost. Consider assigning realloc() to a temporary pointer. file.c 169


static int
code_page_i(....)
{
  table = realloc(table, count * sizeof(*table));
  if (!table) return ST_CONTINUE;
  ....
}

ReOpenLDAP

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'lud.lud_exts' is lost. Consider assigning realloc() to a temporary pointer. ldapurl.c 306


int
main( int argc, char *argv[])
{
  ....
  lud.lud_exts = (char **)realloc( lud.lud_exts,
    sizeof( char * ) * ( nexts + 2 ) );
  ....
}

Partio

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'attributeData[i]' is lost. Consider assigning realloc() to a temporary pointer. ParticleSimple.cpp 266


ParticleIndex ParticlesSimple::
addParticle()
{
  ....
  for(unsigned int i=0;i<attributes.size();i++)
    attributeData[i]=
                  (char*)realloc(attributeData[i],
                                (size_t)attributeStrides[i]*
                                (size_t)allocatedCount);
  ....
}

Similar errors can be found in some other places:

  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'attributeData[i]' is lost. Consider assigning realloc() to a temporary pointer. ParticleSimple.cpp 280
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'data' is lost. Consider assigning realloc() to a temporary pointer. ParticleSimpleInterleave.cpp 281
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'data' is lost. Consider assigning realloc() to a temporary pointer. ParticleSimpleInterleave.cpp 292

OpenSubdiv

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'm_blocks' is lost. Consider assigning realloc() to a temporary pointer. allocator.h 145


template <typename T>
T* HbrAllocator<T>::Allocate()
{
  ....
  // Keep track of the newly allocated block
  if (m_nblocks + 1 >= m_blockCapacity) {
      m_blockCapacity = m_blockCapacity * 2;
      if (m_blockCapacity < 1) m_blockCapacity = 1;
      m_blocks = (T**) realloc(m_blocks,
                               m_blockCapacity * sizeof(T*));
  }
  m_blocks[m_nblocks] = block;
  ....
}

EFL Core Libraries

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'rects->rects' is lost. Consider assigning realloc() to a temporary pointer. evas_inline.x 67


static inline Cutout_Rect*
evas_common_draw_context_cutouts_add(Cutout_Rects* rects,
                                     int x, int y, int w, int h)
{
   Cutout_Rect* rect;

   if (rects->max < (rects->active + 1))
   {
     rects->max += 512;
     rects->rects = (Cutout_Rect *)realloc(               // <=
       rects->rects, sizeof(Cutout_Rect) * rects->max);
   }

   rect = rects->rects + rects->active;
   rect->x = x;
   rect->y = y;
   rect->w = w;
   rect->h = h;
   rects->active++;

   return rect;
}

Similar errors can be found in some other places:

  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'new_txt' is lost. Consider assigning realloc() to a temporary pointer. eina_str.c 500
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'new_txt' is lost. Consider assigning realloc() to a temporary pointer. eina_str.c 518
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'new_txt' is lost. Consider assigning realloc() to a temporary pointer. eina_str.c 572
  • And 86 additional diagnostic messages.

Tizen

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'value' is lost. Consider assigning realloc() to a temporary pointer. preference.c 951


static int _preference_get_key_filesys(keynode_t *keynode,
                                       int* io_errno)
{
  ....
  char *value = NULL;
  ....
  case PREFERENCE_TYPE_STRING:
    while (fgets(file_buf, sizeof(file_buf), fp)) {
      if (value) {
        value_size = value_size + strlen(file_buf);
        value = (char *) realloc(value, value_size);       // <=
        if (value == NULL) {
          func_ret = PREFERENCE_ERROR_OUT_OF_MEMORY;
          break;
        }
        strncat(value, file_buf, strlen(file_buf));
      } else {
        ....
      }
    }
    ....
    if (value)
      free(value);
    break;
  ....
}

Similar errors can be found in some other places:

  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'gif_data->frames' is lost. Consider assigning realloc() to a temporary pointer. image_util.c 1709
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'gif_data->frames' is lost. Consider assigning realloc() to a temporary pointer. image_util.c 1861
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer '_handle->src_buffer' is lost. Consider assigning realloc() to a temporary pointer. image_util.c 1911
  • And 7 additional diagnostic messages.

Aspell

V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'b->aff' is lost. Consider assigning realloc() to a temporary pointer. aspell.cpp 1914


static inline void add_affix(SML_Table::iterator b, char aff)
{
  char * p = b->aff;
  if (p) {while (*p) {if (*p == aff) return; ++p;}}
  int s = p - b->aff;
  b->aff = (char *)realloc(b->aff, s + 2);
  b->aff[s + 0] = aff;
  b->aff[s + 1] = '\0';
}

Similar errors can be found in some other places:

  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer 'begin_' is lost. Consider assigning realloc() to a temporary pointer. string.cpp 34
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer '(cur)->str' is lost. Consider assigning realloc() to a temporary pointer. prezip.c 103
  • V701 realloc() possible leak: when realloc() fails in allocating memory, original pointer '(cur)->str' is lost. Consider assigning realloc() to a temporary pointer. prezip.c 106
  • And 2 additional diagnostic messages.


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++, and C#

goto PVS-Studio;
On our website we use a cookie to collect information of a technical nature.
If you do not agree, please leave the site. Learn More →
Do not show again