[Spice-devel] [vdagent-win PATCH v10 4/6] Support encoding PNG images

Christophe Fergeau cfergeau at redhat.com
Mon Jul 24 11:59:10 UTC 2017


On Mon, Jul 24, 2017 at 02:15:24PM +0300, Uri Lublin wrote:
> On 07/24/2017 01:22 PM, Christophe Fergeau wrote:
> > On Fri, Jul 21, 2017 at 02:51:39PM +0100, Frediano Ziglio wrote:
> > > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > > Acked-by: Christophe Fergeau <cfergeau at redhat.com>
> > > ---
> > >   vdagent/imagepng.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++++++++--
> > >   1 file changed, 106 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/vdagent/imagepng.cpp b/vdagent/imagepng.cpp
> > > index 5642cc9..8a759f7 100644
> > > --- a/vdagent/imagepng.cpp
> > > +++ b/vdagent/imagepng.cpp
> > > @@ -19,6 +19,7 @@
> > >   #include <png.h>
> > >   #include <algorithm>
> > > +#include <vector>
> > >   #include "imagepng.h"
> > > @@ -36,9 +37,13 @@ private:
> > >   struct BufferIo {
> > >       uint8_t *buf;
> > >       uint32_t pos, size;
> > > +    bool allocated;
> > >       BufferIo(uint8_t *_buf, uint32_t _size):
> > > -        buf(_buf), pos(0), size(_size)
> > > +        buf(_buf), pos(0), size(_size),
> > > +        allocated(false)
> > >       {}
> > > +    ~BufferIo() { if (allocated) free(buf); }
> > > +    uint8_t *release() { allocated = false; return buf; }
> > >   };
> > >   static void read_from_bufio(png_structp png, png_bytep out, png_size_t size)
> > > @@ -50,6 +55,29 @@ static void read_from_bufio(png_structp png, png_bytep out, png_size_t size)
> > >       io.pos += size;
> > >   }
> > > +static void write_to_bufio(png_structp png, png_bytep in, png_size_t size)
> > > +{
> > > +    BufferIo& io(*(BufferIo*)png_get_io_ptr(png));
> > > +    if (io.pos + size > io.size) {
> > > +        uint32_t new_size = io.size ? io.size * 2 : 4096;
> > > +        while (io.pos + size >= new_size) {
> > > +            new_size *= 2;
> > > +        }
> > > +        uint8_t *p = (uint8_t*) realloc(io.buf, new_size);
> > 
> > you are missing a if (!allocated) io.buf = NULL; here.
> 
> Why is that ? if (!allocated) then io.buf is not freed.

What I mean is that you don't want to try to realloc(my_non_allocated_buffer);

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170724/78846d2c/attachment.sig>


More information about the Spice-devel mailing list