From 333550895561e182d4a18c8872b1c76d27df4961 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 26 Mar 2017 15:41:34 +0200 Subject: [PATCH] Memory leaks and delete operator fixes. (pull request #168) --- source/src/crypto.cpp | 6 +++++- source/src/main.cpp | 1 + source/src/stream.cpp | 2 +- source/src/worldio.cpp | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/source/src/crypto.cpp b/source/src/crypto.cpp index 56fc3fed..4d5db616 100644 --- a/source/src/crypto.cpp +++ b/source/src/crypto.cpp @@ -985,6 +985,10 @@ void authkey_(char **args, int numargs) // set up misc keys } conoutf("authkey %s generated.", ak->name); } + else + { + delete ak; + } } } else if(!strcasecmp(args[0], "ADD")) @@ -993,7 +997,7 @@ void authkey_(char **args, int numargs) // set up misc keys { delauthkey(args[1]); authkey *ak = new authkey(args[1], args[2]); - if(ak->name) authkeys.add(ak); + if(ak->name) authkeys.add(ak); else delete ak; } } else if(!strcasecmp(args[0], "SELFCERT")) diff --git a/source/src/main.cpp b/source/src/main.cpp index e63848b7..b8bd02e1 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -298,6 +298,7 @@ void mapscreenshot(const char *imagepath, bool mapshot, int fileformat) { conoutf("no mapshot prepared!"); SDL_FreeSurface(image); + delete[] tmpdst; return; } loopi(dst_h) diff --git a/source/src/stream.cpp b/source/src/stream.cpp index 44d7cbb2..d68dde60 100644 --- a/source/src/stream.cpp +++ b/source/src/stream.cpp @@ -934,7 +934,7 @@ stream *opengzfile(const char *filename, const char *mode, stream *file, int lev stream *source = file ? file : openfile(filename, mode); if(!source) return NULL; gzstream *gz = new gzstream; - if(!gz->open(source, mode, !file, level)) { if(!file) delete source; return NULL; } + if(!gz->open(source, mode, !file, level)) { if(!file) delete source; delete gz; return NULL; } return gz; } diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index ea1be513..131fb64d 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -1149,7 +1149,7 @@ struct xmap ~xmap() { headerextras.deletecontents(); - delete world; + delete[] world; ents.setsize(0); delents.setsize(0); mapconfig.setsize(0);