public inbox for cygwin-apps-cvs@sourceware.org
help / color / mirror / Atom feed
* [setup - the official Cygwin setup program used to install Cygwin and keep it up to date] branch master, updated. release_2.874-25-gf882d56
@ 2016-09-01 12:46 corinna
  0 siblings, 0 replies; only message in thread
From: corinna @ 2016-09-01 12:46 UTC (permalink / raw)
  To: cygwin-apps-cvs




https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=f882d56e593fe2338e4eb7c444719c4e8697fd87

commit f882d56e593fe2338e4eb7c444719c4e8697fd87
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Thu Sep 1 14:46:21 2016 +0200

    Fix invalid deleting of a local pointer in UserSettings::UserSettings
    
    Convert buf to a unique_ptr instead.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>


Diff:
---
 UserSettings.cc |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/UserSettings.cc b/UserSettings.cc
index dd50c52..f4917ec 100644
--- a/UserSettings.cc
+++ b/UserSettings.cc
@@ -13,6 +13,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <memory>
 #include "UserSettings.h"
 #include "io_stream.h"
 #include "win32.h"
@@ -92,15 +93,15 @@ UserSettings::UserSettings (std::string local_dir)
     return;
 
   size_t sz = f->get_size ();
-  char *buf = new char [sz + 2];
-  ssize_t szread = f->read (buf, sz);
+  std::unique_ptr<char[]> buf (new char [sz + 2]);
+  ssize_t szread = f->read (buf.get (), sz);
   delete f;
 
   if (szread > 0)
     {
       buf[szread] = '\0';
       buf[szread + 1] = '\0';
-      for (char *p = strtok (buf, "\n"); p; p = strtok (p, "\n"))
+      for (char *p = strtok (buf.get (), "\n"); p; p = strtok (p, "\n"))
 	{
 	  char *eol = strchr (p, '\0');
 	  char *thiskey = trim (p);
@@ -131,7 +132,6 @@ UserSettings::UserSettings (std::string local_dir)
 	  set (thiskey, thisval);
 	}
     }
-  delete buf;
 }
 
 unsigned int


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-09-01 12:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-01 12:46 [setup - the official Cygwin setup program used to install Cygwin and keep it up to date] branch master, updated. release_2.874-25-gf882d56 corinna

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).