From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.1 From: Aleksei Nikiforov To: devel@lists.altlinux.org Date: Thu, 12 Dec 2019 12:57:24 +0300 Message-Id: <20191212095730.83787-16-darktemplar@altlinux.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191212095730.83787-1-darktemplar@altlinux.org> References: <20191211234857.GB17949@altlinux.org> <20191212095730.83787-1-darktemplar@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Aleksei Nikiforov Subject: [devel] [PATCH for apt v2 15/21] Fix incorrect delete operator X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Dec 2019 09:58:35 -0000 Archived-At: List-Archive: List-Post: Found via clang-static-analyzer: Memory error: Bad deallocator: Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete' --- apt/methods/rsync.cc | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/apt/methods/rsync.cc b/apt/methods/rsync.cc index 1fc6a36..efc1c0e 100644 --- a/apt/methods/rsync.cc +++ b/apt/methods/rsync.cc @@ -26,6 +26,7 @@ RSYNC Aquire Method - This is the RSYNC aquire method for APT. #include #include #include +#include // Internet stuff #include @@ -277,13 +278,10 @@ void RsyncMethod::RsyncConnExec::ParseOutput(pkgAcqMethod *Owner, FetchResult &F while (*ptr2!=0 && !isspace(*ptr2)) ++ptr2; if (ptr!=ptr2) { - char *tmpfn = new char[ptr2-ptr+1]; - bzero(tmpfn, ptr2-ptr+1); - strncpy(tmpfn, ptr, ptr2-ptr); + std::string tmpfn(ptr, ptr2-ptr); if (RsyncMethod::Debug) cerr << endl << "RSYNC: " << TMPFN << tmpfn << endl; - FRes.TmpFilename = string(tmpfn); - delete tmpfn; + FRes.TmpFilename = std::move(tmpfn); } } @@ -314,13 +312,10 @@ void RsyncMethod::RsyncConnExec::ParseOutput(pkgAcqMethod *Owner, FetchResult &F while (*ptr2!=0 && *ptr2!='\n') ++ptr2; if (ptr!=ptr2) { - char *tmp = new char[ptr2-ptr+1]; - bzero(tmp, ptr2-ptr+1); - strncpy(tmp, ptr, ptr2-ptr); - _error->Error("%s",tmp); + std::string tmp(ptr, ptr2-ptr); + _error->Error("%s",tmp.c_str()); if (RsyncMethod::Debug) cerr << endl << FAILED << tmp << endl; - delete tmp; } else { _error->Error("Child process failed (no description)"); } @@ -431,13 +426,10 @@ void RsyncMethod::RsyncConnExecExt::ParseOutput(pkgAcqMethod *Owner, FetchResult while (*ptr2!=0 && !isspace(*ptr2)) ++ptr2; if (ptr!=ptr2) { - char *tmpfn = new char[ptr2-ptr+1]; - bzero(tmpfn, ptr2-ptr+1); - strncpy(tmpfn, ptr, ptr2-ptr); + std::string tmpfn(ptr, ptr2-ptr); if (RsyncMethod::Debug) cerr << endl << "RSYNC: " << TMPFN << tmpfn << endl; - FRes.TmpFilename = string(tmpfn); - delete tmpfn; + FRes.TmpFilename = std::move(tmpfn); } } @@ -468,13 +460,10 @@ void RsyncMethod::RsyncConnExecExt::ParseOutput(pkgAcqMethod *Owner, FetchResult while (*ptr2!=0 && *ptr2!='\n') ++ptr2; if (ptr!=ptr2) { - char *tmp = new char[ptr2-ptr+1]; - bzero(tmp, ptr2-ptr+1); - strncpy(tmp, ptr, ptr2-ptr); - _error->Error("%s",tmp); + std::string tmp(ptr, ptr2-ptr); + _error->Error("%s",tmp.c_str()); if (RsyncMethod::Debug) cerr << endl << FAILED << tmp << endl; - delete tmp; } else { _error->Error("Child process failed (no description)"); } -- 2.24.1