[Spice-devel] [vdagent-win PATCH] Remove small memory leak in log_version

Christophe Fergeau cfergeau at redhat.com
Fri Jul 21 14:12:02 UTC 2017


On Fri, Jul 21, 2017 at 09:58:59AM -0400, Frediano Ziglio wrote:
> > 
> > >  
> > >  #define LOG_ROLL_SIZE (1024 * 1024)
> > >  
> > > @@ -80,7 +81,6 @@ void log_version()
> > >  {
> > >      DWORD handle;
> > >      TCHAR module_fname[MAX_PATH];
> > > -    TCHAR* info_buf = NULL;
> > >  
> > >      try {
> > >          if (!GetModuleFileName(NULL, module_fname, MAX_PATH)) {
> > > @@ -90,13 +90,13 @@ void log_version()
> > >          if (version_inf_size == 0) {
> > >              throw;
> 
> Another OT... what's this throw? This is going to terminate the program,
> throw alone is for raising the current exception but there's no
> current exception here.

I'd say the goal was to go to the catch(...) block below, just not done
correctly.

> 
> > >          }
> > > -        TCHAR* info_buf = new TCHAR[version_inf_size];
> > > -        if (!GetFileVersionInfo(module_fname, handle, version_inf_size,
> > > info_buf)) {
> > > +        std::vector<TCHAR> info_buf(version_inf_size);
> > > +        if (!GetFileVersionInfo(module_fname, handle, version_inf_size,
> > > &info_buf[0])) {
> > >              throw;
> > >          }
> > >          UINT size;
> > >          VS_FIXEDFILEINFO* file_info;
> > > -        if (!VerQueryValue(info_buf, L"\\", (VOID**)&file_info, &size) ||
> > > +        if (!VerQueryValue(&info_buf[0], L"\\", (VOID**)&file_info, &size)
> > > ||
> > >                  size < sizeof(VS_FIXEDFILEINFO)) {
> > >              throw;
> > >          }
> > > @@ -108,5 +108,4 @@ void log_version()
> > >      } catch (...) {
> > >          vd_printf("get version info failed");
> > >      }
> > > -    delete[] info_buf;
> > >  }
> 
> Frediano
-------------- 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/20170721/ecd474e0/attachment-0001.sig>


More information about the Spice-devel mailing list