diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-06-02 18:41:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-06-02 23:00:56 +0300 |
commit | 6d97cdf25db274a81e9d9edc417b51cf44152733 (patch) | |
tree | 142f1cc00b1733bb54980a863932c96c7a98fa73 /src | |
parent | 6b83725f3acf5a1e4dd08f4f243609fc66a38c22 (diff) | |
download | plus-6d97cdf25db274a81e9d9edc417b51cf44152733.tar.gz plus-6d97cdf25db274a81e9d9edc417b51cf44152733.tar.bz2 plus-6d97cdf25db274a81e9d9edc417b51cf44152733.tar.xz plus-6d97cdf25db274a81e9d9edc417b51cf44152733.zip |
Fix some memory leaks and missing initialisations.
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 3 | ||||
-rw-r--r-- | src/configuration.cpp | 1 | ||||
-rw-r--r-- | src/gui/minimap.cpp | 18 | ||||
-rw-r--r-- | src/gui/minimap.h | 1 | ||||
-rw-r--r-- | src/gui/whoisonline.cpp | 5 | ||||
-rw-r--r-- | src/gui/widgets/button.cpp | 7 | ||||
-rw-r--r-- | src/guichan/widgets/radiobutton.cpp | 9 | ||||
-rw-r--r-- | src/net/download.cpp | 2 | ||||
-rw-r--r-- | src/net/tmwa/network.cpp | 1 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 2 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 2 | ||||
-rw-r--r-- | src/utils/base64.cpp | 7 | ||||
-rw-r--r-- | src/utils/copynpaste.cpp | 2 |
13 files changed, 46 insertions, 14 deletions
diff --git a/src/client.cpp b/src/client.cpp index b9a1b56a6..eaf6cb309 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -624,6 +624,9 @@ Client::~Client() config.write(); serverConfig.write(); + config.clear(); + serverConfig.clear(); + logger->log1("Quitting11"); delete chatLogger; diff --git a/src/configuration.cpp b/src/configuration.cpp index ffb80ad13..abeb4b2af 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -134,6 +134,7 @@ void ConfigurationObject::clear() deleteList(it->first); } mOptions.clear(); + mContainerOptions.clear(); } ConfigurationObject::~ConfigurationObject() diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index b85826679..32887466c 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -49,7 +49,8 @@ Minimap::Minimap(): Window(_("Map")), mMapImage(0), mWidthProportion(0.5), - mHeightProportion(0.5) + mHeightProportion(0.5), + mCustomMapImage(false) { setWindowName("Minimap"); mShow = config.getValueBool(getWindowName() + "Show", true); @@ -74,7 +75,13 @@ Minimap::~Minimap() config.setValue(getWindowName() + "Show", mShow); if (mMapImage) - mMapImage->decRef(); + { + if (mCustomMapImage) + delete mMapImage; + else + mMapImage->decRef(); + mMapImage = 0; + } } void Minimap::setMap(Map *map) @@ -93,7 +100,10 @@ void Minimap::setMap(Map *map) // Adapt the image if (mMapImage) { - mMapImage->decRef(); + if (mCustomMapImage) + delete mMapImage; + else + mMapImage->decRef(); mMapImage = 0; } @@ -129,6 +139,7 @@ void Minimap::setMap(Map *map) mMapImage = Image::load(surface); mMapImage->setAlpha(Client::getGuiAlpha()); + mCustomMapImage = true; SDL_FreeSurface(surface); } else @@ -143,6 +154,7 @@ void Minimap::setMap(Map *map) minimapName = tempname; mMapImage = resman->getImage(minimapName); + mCustomMapImage = false; } } diff --git a/src/gui/minimap.h b/src/gui/minimap.h index e75dfddc1..33e0f14ee 100644 --- a/src/gui/minimap.h +++ b/src/gui/minimap.h @@ -63,6 +63,7 @@ class Minimap : public Window float mWidthProportion; float mHeightProportion; static bool mShow; + bool mCustomMapImage; }; extern Minimap *minimap; diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index dfb896778..73b6e2e8c 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -368,6 +368,7 @@ int WhoIsOnline::downloadThread(void *ptr) if (!wio->mAllowUpdate) { curl_easy_cleanup(curl); + curl = 0; break; } wio->mDownloadedBytes = 0; @@ -410,11 +411,13 @@ int WhoIsOnline::downloadThread(void *ptr) break; } attempts++; + curl_easy_cleanup(curl); + curl_slist_free_all(pHeaders); + curl = 0; continue; } curl_easy_cleanup(curl); - curl_slist_free_all(pHeaders); // It's stored in memory, we're done diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index ba3ac5f36..0bc5ec9ef 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -71,6 +71,7 @@ ImageRect Button::button[BUTTON_COUNT]; Button::Button(): mDescription(""), mClickCount(0), + mTag(0), mVertexes(new GraphicsVertexes()), mRedraw(true), mMode(0), @@ -84,8 +85,12 @@ Button::Button(const std::string &caption, const std::string &actionEventId, gcn::ActionListener *listener): gcn::Button(caption), mDescription(""), mClickCount(0), + mTag(0), mVertexes(new GraphicsVertexes()), - mRedraw(true) + mRedraw(true), + mMode(0), + mXOffset(0), + mYOffset(0) { init(); setActionEventId(actionEventId); diff --git a/src/guichan/widgets/radiobutton.cpp b/src/guichan/widgets/radiobutton.cpp index 2cada912a..37fd4a0f0 100644 --- a/src/guichan/widgets/radiobutton.cpp +++ b/src/guichan/widgets/radiobutton.cpp @@ -58,7 +58,10 @@ namespace gcn { RadioButton::GroupMap RadioButton::mGroupMap; - RadioButton::RadioButton() + RadioButton::RadioButton() : + mSelected(false), + mCaption(""), + mGroup("") { setSelected(false); @@ -69,7 +72,9 @@ namespace gcn RadioButton::RadioButton(const std::string &caption, const std::string &group, - bool selected) + bool selected) : + mSelected(false), + mGroup("") { setCaption(caption); setGroup(group); diff --git a/src/net/download.cpp b/src/net/download.cpp index 1da792c52..59f6edd9c 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -61,7 +61,7 @@ Download::Download(void *ptr, const std::string &url, mHeaders(NULL), mIgnoreError(ignoreError) { - mError = static_cast<char*>(malloc(CURL_ERROR_SIZE + 1)); + mError = static_cast<char*>(calloc(CURL_ERROR_SIZE + 1, 1)); mError[0] = 0; mOptions.cancel = false; diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 9207522e1..dbc4ff97e 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -129,6 +129,7 @@ Network::~Network() disconnect(); SDL_DestroyMutex(mMutex); + mMutex = 0; mInstance = 0; delete[] mInBuffer; diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index c5e52ae7c..fb0298457 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -86,7 +86,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, int ret; z_stream strm; - out = static_cast<unsigned char*>(malloc(bufferSize)); + out = static_cast<unsigned char*>(calloc(bufferSize, 1)); strm.zalloc = Z_NULL; strm.zfree = Z_NULL; diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index a86edbb6f..aea598935 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -584,7 +584,7 @@ void *ResourceManager::loadFile(const std::string &fileName, int &fileSize) fileSize = static_cast<int>(PHYSFS_fileLength(file)); // Allocate memory and load the file - void *buffer = malloc(fileSize); + void *buffer = calloc(fileSize, 1); PHYSFS_read(file, buffer, 1, fileSize); // Close the file and let the user deallocate the memory diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp index d3563fb78..14876d878 100644 --- a/src/utils/base64.cpp +++ b/src/utils/base64.cpp @@ -49,8 +49,8 @@ unsigned char *php3_base64_encode(const unsigned char *string, { const unsigned char *current = string; int i = 0; - unsigned char *result = static_cast<unsigned char *>(malloc( - ((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char))); + unsigned char *result = static_cast<unsigned char *>(calloc( + ((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char), 1)); while (length > 2) { /* keep going until we have less than 24 bits */ @@ -99,7 +99,8 @@ unsigned char *php3_base64_decode(const unsigned char *string, int ch, i = 0, j = 0, k; char *chp; - unsigned char *result = static_cast<unsigned char *>(malloc(length + 1)); + unsigned char *result = static_cast<unsigned char *>( + calloc(length + 1, 1)); if (result == NULL) return NULL; diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp index 58740a243..5b1ccb5bc 100644 --- a/src/utils/copynpaste.cpp +++ b/src/utils/copynpaste.cpp @@ -57,7 +57,7 @@ bool retrieveBuffer(std::string& text, std::string::size_type& pos) if (len > 0) { // Convert from UTF-16 to UTF-8 - void *temp = malloc(len); + void *temp = calloc(len, 1); if (WideCharToMultiByte(CP_UTF8, 0, data, -1, (LPSTR)temp, len, NULL, NULL)) { |