From 2dfc384cde46ba63ed7c2f4420712596096123ca Mon Sep 17 00:00:00 2001 From: danieldg Date: Fri, 17 Apr 2009 13:54:53 +0000 Subject: Fix SetModeParam to use std::string and handle edge cases. Previously, changing the vaule of a mode could require 3 calls to SetMode and SetModeParam. This also fixes memory leaks caused by the strdup() not always being paired with a free(). git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11307 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/channels.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/channels.cpp') diff --git a/src/channels.cpp b/src/channels.cpp index 19899d300..99b118d0d 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -34,27 +34,22 @@ Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : Serv void Channel::SetMode(char mode,bool mode_on) { modes[mode-65] = mode_on; - if (!mode_on) - this->SetModeParam(mode,"",false); } - -void Channel::SetModeParam(char mode,const char* parameter,bool mode_on) +void Channel::SetMode(char mode, std::string parameter) { CustomModeList::iterator n = custom_mode_params.find(mode); - - if (mode_on) + // always erase, even if changing, so that the map gets the new value + if (n != custom_mode_params.end()) + custom_mode_params.erase(n); + if (parameter.empty()) { - if (n == custom_mode_params.end()) - custom_mode_params[mode] = strdup(parameter); + modes[mode-65] = false; } else { - if (n != custom_mode_params.end()) - { - free(n->second); - custom_mode_params.erase(n); - } + custom_mode_params[mode] = parameter; + modes[mode-65] = true; } } -- cgit v1.3.1-10-gc9f91