POV-Ray : Newsgroups : povray.programming : Memory leak in pvbmp.c (POV-Ray windows version) : Memory leak in pvbmp.c (POV-Ray windows version) Server Time
28 Jul 2024 12:36:31 EDT (-0400)
  Memory leak in pvbmp.c (POV-Ray windows version)  
From: Vahur Krouverk
Date: 5 Mar 2001 12:52:03
Message: <3AA3D257.E2D0E519@aetec.ee>
Hello!

(Don't know, if this is already reported. If there were search engine
for news server... [hint, hint])
I found a memory leak in pvbmp.c. It seems to be present in most recent
version of official POV-Ray (v. 3.1g) and if v. 3.5 is based on same
Windows code, then it will be relevant to new version as well (or may-be
it is already corrected?)
Memory leak is in pvbmp.c file, line 744, where buffer is allocated for
filling bitmap file with line info, containing in the beginning BMP
magic bytes, but this buffer is never released. 
====================8<===================
      magic = POV_MALLOC(((*width*24+31)/32)*4, "BMP magic"); 
<---allocation
      memset(magic, 0, ((*width*24+31)/32)*4);
      magic[0] = MAGIC1;
      magic[1] = MAGIC2;
      magic[2] = MAGIC3;
      for (i=0; i<*height; i++)
        fwrite(magic, ((*width*24+31)/32)*4, 1, f);
        <---no freeing!
      break;
====================8<===================
Additionally, this code could be more effective, if instead of
calculating same expression for buffer size 3 times it is calculated
once and held in temporary variable. Moreover, for() loop is
unneccessary, instead fwrite could be used with count parameter (2nd
parameter) equal to *height.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.