Browse Source

Use std::string for string memory management

Avoids a bit of complexity by delegating that handling to a string
object.
pull/1587/head
Pierre Ossman 1 year ago
parent
commit
adaedc9629

+ 2
- 11
common/rfb/Blacklist.cxx View File

@@ -45,11 +45,6 @@ Blacklist::Blacklist() {
}

Blacklist::~Blacklist() {
// Free the map keys
BlacklistMap::iterator i;
for (i=blm.begin(); i!=blm.end(); i++) {
strFree((char*)(*i).first);
}
}

bool Blacklist::isBlackmarked(const char* name) {
@@ -65,7 +60,7 @@ bool Blacklist::isBlackmarked(const char* name) {
bi.marks = 1;
bi.blockUntil = 0;
bi.blockTimeout = initialTimeout;
blm[strDup(name)] = bi;
blm[name] = bi;
i = blm.find(name);
}

@@ -92,9 +87,5 @@ bool Blacklist::isBlackmarked(const char* name) {
}

void Blacklist::clearBlackmark(const char* name) {
BlacklistMap::iterator i = blm.find(name);
if (i != blm.end()) {
strFree((char*)(*i).first);
blm.erase(i);
}
blm.erase(name);
}

+ 2
- 7
common/rfb/Blacklist.h View File

@@ -30,9 +30,9 @@
#include <string.h>
#include <time.h>
#include <map>
#include <string>

#include <rfb/Configuration.h>
#include <rfb/util.h>

namespace rfb {

@@ -68,17 +68,12 @@ namespace rfb {
void clearBlackmark(const char* name);

protected:
struct ltStr {
bool operator()(const char* s1, const char* s2) const {
return strcmp(s1, s2) < 0;
};
};
struct BlacklistInfo {
int marks;
time_t blockUntil;
unsigned int blockTimeout;
};
typedef std::map<const char*,BlacklistInfo,ltStr> BlacklistMap;
typedef std::map<std::string,BlacklistInfo> BlacklistMap;
BlacklistMap blm;
};


+ 9
- 17
common/rfb/CConnection.cxx View File

@@ -59,7 +59,7 @@ CConnection::CConnection()
firstUpdate(true), pendingUpdate(false), continuousUpdates(false),
forceNonincremental(true),
framebuffer(NULL), decoder(this),
serverClipboard(NULL), hasLocalClipboard(false)
hasRemoteClipboard(false), hasLocalClipboard(false)
{
}

@@ -405,8 +405,6 @@ void CConnection::close()
reader_ = NULL;
delete writer_;
writer_ = NULL;
strFree(serverClipboard);
serverClipboard = NULL;
}

void CConnection::setDesktopSize(int w, int h)
@@ -545,10 +543,8 @@ void CConnection::serverCutText(const char* str)
{
hasLocalClipboard = false;

strFree(serverClipboard);
serverClipboard = NULL;

serverClipboard = strDup(latin1ToUTF8(str).c_str());
serverClipboard = latin1ToUTF8(str);
hasRemoteClipboard = true;

handleClipboardAnnounce(true);
}
@@ -589,8 +585,7 @@ void CConnection::handleClipboardPeek()

void CConnection::handleClipboardNotify(uint32_t flags)
{
strFree(serverClipboard);
serverClipboard = NULL;
hasRemoteClipboard = false;

if (flags & rfb::clipboardUTF8) {
hasLocalClipboard = false;
@@ -609,14 +604,11 @@ void CConnection::handleClipboardProvide(uint32_t flags,
return;
}

strFree(serverClipboard);
serverClipboard = NULL;

std::string filtered(convertLF((const char*)data[0], lengths[0]));
serverClipboard = strDup(filtered.c_str());
serverClipboard = convertLF((const char*)data[0], lengths[0]);
hasRemoteClipboard = true;

// FIXME: Should probably verify that this data was actually requested
handleClipboardData(serverClipboard);
handleClipboardData(serverClipboard.c_str());
}

void CConnection::authSuccess()
@@ -646,8 +638,8 @@ void CConnection::handleClipboardData(const char* /*data*/)

void CConnection::requestClipboard()
{
if (serverClipboard != NULL) {
handleClipboardData(serverClipboard);
if (hasRemoteClipboard) {
handleClipboardData(serverClipboard.c_str());
return;
}


+ 4
- 1
common/rfb/CConnection.h View File

@@ -24,6 +24,8 @@
#ifndef __RFB_CCONNECTION_H__
#define __RFB_CCONNECTION_H__

#include <string>

#include <rfb/CMsgHandler.h>
#include <rfb/DecodeManager.h>
#include <rfb/SecurityClient.h>
@@ -292,7 +294,8 @@ namespace rfb {
ModifiablePixelBuffer* framebuffer;
DecodeManager decoder;

char* serverClipboard;
std::string serverClipboard;
bool hasRemoteClipboard;
bool hasLocalClipboard;
bool unsolicitedClipboardAttempt;
};

+ 2
- 4
common/rfb/ClientParams.cxx View File

@@ -34,7 +34,7 @@ ClientParams::ClientParams()
: majorVersion(0), minorVersion(0),
compressLevel(2), qualityLevel(-1), fineQualityLevel(-1),
subsampling(subsampleUndefined),
width_(0), height_(0), name_(0),
width_(0), height_(0),
cursorPos_(0, 0), ledState_(ledUnknown)
{
setName("");
@@ -49,7 +49,6 @@ ClientParams::ClientParams()

ClientParams::~ClientParams()
{
delete [] name_;
delete cursor_;
}

@@ -80,8 +79,7 @@ void ClientParams::setPF(const PixelFormat& pf)

void ClientParams::setName(const char* name)
{
delete [] name_;
name_ = strDup(name);
name_ = name;
}

void ClientParams::setCursor(const Cursor& other)

+ 3
- 2
common/rfb/ClientParams.h View File

@@ -24,6 +24,7 @@
#define __RFB_CLIENTPARAMS_H__

#include <set>
#include <string>

#include <stdint.h>

@@ -72,7 +73,7 @@ namespace rfb {
const PixelFormat& pf() const { return pf_; }
void setPF(const PixelFormat& pf);

const char* name() const { return name_; }
const char* name() const { return name_.c_str(); }
void setName(const char* name);

const Cursor& cursor() const { return *cursor_; }
@@ -113,7 +114,7 @@ namespace rfb {
ScreenSet screenLayout_;

PixelFormat pf_;
char* name_;
std::string name_;
Cursor* cursor_;
Point cursorPos_;
std::set<int32_t> encodings_;

+ 5
- 8
common/rfb/Configuration.cxx View File

@@ -372,7 +372,7 @@ IntParameter::operator int() const {

StringParameter::StringParameter(const char* name_, const char* desc_,
const char* v, ConfigurationObject co)
: VoidParameter(name_, desc_, co), value(strDup(v)), def_value(strDup(v))
: VoidParameter(name_, desc_, co), value(v), def_value(v)
{
if (!v) {
vlog.error("Default value <null> for %s not allowed",name_);
@@ -381,8 +381,6 @@ StringParameter::StringParameter(const char* name_, const char* desc_,
}

StringParameter::~StringParameter() {
strFree(value);
strFree(def_value);
}

bool StringParameter::setParam(const char* v) {
@@ -391,9 +389,8 @@ bool StringParameter::setParam(const char* v) {
if (!v)
throw rfb::Exception("setParam(<null>) not allowed");
vlog.debug("set %s(String) to %s", getName(), v);
CharArray oldValue(value);
value = strDup(v);
return value != 0;
value = v;
return true;
}

std::string StringParameter::getDefaultStr() const {
@@ -402,11 +399,11 @@ std::string StringParameter::getDefaultStr() const {

std::string StringParameter::getValueStr() const {
LOCK_CONFIG;
return std::string(value);
return value;
}

StringParameter::operator const char *() const {
return value;
return value.c_str();
}

// -=- BinaryParameter

+ 2
- 2
common/rfb/Configuration.h View File

@@ -250,8 +250,8 @@ namespace rfb {
virtual std::string getValueStr() const;
operator const char*() const;
protected:
char* value;
char* def_value;
std::string value;
std::string def_value;
};

class BinaryParameter : public VoidParameter {

+ 1
- 1
common/rfb/KeyRemapper.cxx View File

@@ -87,7 +87,7 @@ class KeyMapParameter : public StringParameter {
public:
KeyMapParameter()
: StringParameter("RemapKeys", "Comma-separated list of incoming keysyms to remap. Mappings are expressed as two hex values, prefixed by 0x, and separated by ->", "") {
setParam(value);
KeyRemapper::defInstance.setMapping("");
}
bool setParam(const char* v) {
KeyRemapper::defInstance.setMapping(v);

+ 10
- 17
common/rfb/SConnection.cxx View File

@@ -60,7 +60,8 @@ SConnection::SConnection()
is(0), os(0), reader_(0), writer_(0), ssecurity(0),
authFailureTimer(this, &SConnection::handleAuthFailureTimeout),
state_(RFBSTATE_UNINITIALISED), preferredEncoding(encodingRaw),
accessRights(0x0000), clientClipboard(NULL), hasLocalClipboard(false),
accessRights(0x0000), hasRemoteClipboard(false),
hasLocalClipboard(false),
unsolicitedClipboardAttempt(false)
{
defaultMajorVersion = 3;
@@ -380,10 +381,8 @@ void SConnection::clientCutText(const char* str)
{
hasLocalClipboard = false;

strFree(clientClipboard);
clientClipboard = NULL;

clientClipboard = strDup(latin1ToUTF8(str).c_str());
clientClipboard = latin1ToUTF8(str);
hasRemoteClipboard = true;

handleClipboardAnnounce(true);
}
@@ -409,8 +408,7 @@ void SConnection::handleClipboardPeek()

void SConnection::handleClipboardNotify(uint32_t flags)
{
strFree(clientClipboard);
clientClipboard = NULL;
hasRemoteClipboard = false;

if (flags & rfb::clipboardUTF8) {
hasLocalClipboard = false;
@@ -429,14 +427,11 @@ void SConnection::handleClipboardProvide(uint32_t flags,
return;
}

strFree(clientClipboard);
clientClipboard = NULL;

std::string filtered(convertLF((const char*)data[0], lengths[0]));
clientClipboard = strDup(filtered.c_str());
clientClipboard = convertLF((const char*)data[0], lengths[0]);
hasRemoteClipboard = true;

// FIXME: Should probably verify that this data was actually requested
handleClipboardData(clientClipboard);
handleClipboardData(clientClipboard.c_str());
}

void SConnection::supportsQEMUKeyEvent()
@@ -554,8 +549,8 @@ void SConnection::handleClipboardData(const char* /*data*/)

void SConnection::requestClipboard()
{
if (clientClipboard != NULL) {
handleClipboardData(clientClipboard);
if (hasRemoteClipboard) {
handleClipboardData(clientClipboard.c_str());
return;
}

@@ -624,8 +619,6 @@ void SConnection::cleanup()
reader_ = NULL;
delete writer_;
writer_ = NULL;
strFree(clientClipboard);
clientClipboard = NULL;
}

void SConnection::writeFakeColourMap(void)

+ 4
- 1
common/rfb/SConnection.h View File

@@ -24,6 +24,8 @@
#ifndef __RFB_SCONNECTION_H__
#define __RFB_SCONNECTION_H__

#include <string>

#include <rdr/InStream.h>
#include <rdr/OutStream.h>

@@ -263,7 +265,8 @@ namespace rfb {
int32_t preferredEncoding;
AccessRights accessRights;

char* clientClipboard;
std::string clientClipboard;
bool hasRemoteClipboard;
bool hasLocalClipboard;
bool unsolicitedClipboardAttempt;
};

+ 2
- 4
common/rfb/ServerParams.cxx View File

@@ -33,7 +33,7 @@ ServerParams::ServerParams()
supportsQEMUKeyEvent(false),
supportsSetDesktopSize(false), supportsFence(false),
supportsContinuousUpdates(false),
width_(0), height_(0), name_(0),
width_(0), height_(0),
ledState_(ledUnknown)
{
setName("");
@@ -46,7 +46,6 @@ ServerParams::ServerParams()

ServerParams::~ServerParams()
{
delete [] name_;
delete cursor_;
}

@@ -77,8 +76,7 @@ void ServerParams::setPF(const PixelFormat& pf)

void ServerParams::setName(const char* name)
{
delete [] name_;
name_ = strDup(name);
name_ = name;
}

void ServerParams::setCursor(const Cursor& other)

+ 4
- 2
common/rfb/ServerParams.h View File

@@ -23,6 +23,8 @@
#ifndef __RFB_SERVERPARAMS_H__
#define __RFB_SERVERPARAMS_H__

#include <string>

#include <rfb/Cursor.h>
#include <rfb/PixelFormat.h>
#include <rfb/ScreenSet.h>
@@ -60,7 +62,7 @@ namespace rfb {
const PixelFormat& pf() const { return pf_; }
void setPF(const PixelFormat& pf);

const char* name() const { return name_; }
const char* name() const { return name_.c_str(); }
void setName(const char* name);

const Cursor& cursor() const { return *cursor_; }
@@ -85,7 +87,7 @@ namespace rfb {
ScreenSet screenLayout_;

PixelFormat pf_;
char* name_;
std::string name_;
Cursor* cursor_;
unsigned int ledState_;
uint32_t clipFlags;

+ 1
- 1
vncviewer/MonitorIndicesParameter.cxx View File

@@ -53,7 +53,7 @@ std::set<int> MonitorIndicesParameter::getParam()
return indices;
}

valid = parseIndices(value, &configIndices);
valid = parseIndices(value.c_str(), &configIndices);
if (!valid) {
return indices;
}

+ 9
- 12
vncviewer/ServerDialog.cxx View File

@@ -38,7 +38,6 @@
#include <os/os.h>
#include <rfb/Exception.h>
#include <rfb/LogWriter.h>
#include <rfb/util.h>

#include "fltk/layout.h"
#include "ServerDialog.h"
@@ -62,8 +61,6 @@ ServerDialog::ServerDialog()
Fl_Button *button;
Fl_Box *divider;

usedDir = NULL;

x = OUTER_MARGIN;
y = OUTER_MARGIN;

@@ -120,8 +117,6 @@ ServerDialog::ServerDialog()

ServerDialog::~ServerDialog()
{
if (usedDir)
free(usedDir);
}


@@ -168,10 +163,11 @@ void ServerDialog::handleLoad(Fl_Widget* /*widget*/, void* data)
{
ServerDialog *dialog = (ServerDialog*)data;

if (!dialog->usedDir)
dialog->usedDir = strDup(os::getuserhomedir());
if (dialog->usedDir.empty())
dialog->usedDir = os::getuserhomedir();

Fl_File_Chooser* file_chooser = new Fl_File_Chooser(dialog->usedDir, _("TigerVNC configuration (*.tigervnc)"),
Fl_File_Chooser* file_chooser = new Fl_File_Chooser(dialog->usedDir.c_str(),
_("TigerVNC configuration (*.tigervnc)"),
0, _("Select a TigerVNC configuration file"));
file_chooser->preview(0);
file_chooser->previewButton->hide();
@@ -207,10 +203,11 @@ void ServerDialog::handleSaveAs(Fl_Widget* /*widget*/, void* data)
ServerDialog *dialog = (ServerDialog*)data;
const char* servername = dialog->serverName->value();
const char* filename;
if (!dialog->usedDir)
dialog->usedDir = strDup(os::getuserhomedir());
if (dialog->usedDir.empty())
dialog->usedDir = os::getuserhomedir();
Fl_File_Chooser* file_chooser = new Fl_File_Chooser(dialog->usedDir, _("TigerVNC configuration (*.tigervnc)"),
Fl_File_Chooser* file_chooser = new Fl_File_Chooser(dialog->usedDir.c_str(),
_("TigerVNC configuration (*.tigervnc)"),
2, _("Save the TigerVNC configuration to file"));
file_chooser->preview(0);
@@ -405,6 +402,6 @@ void ServerDialog::saveServerHistory()
void ServerDialog::updateUsedDir(const char* filename)
{
char * name = strdup(filename);
usedDir = strdup(dirname(name));
usedDir = dirname(name);
free(name);
}

+ 1
- 1
vncviewer/ServerDialog.h View File

@@ -50,7 +50,7 @@ private:
protected:
Fl_Input_Choice *serverName;
std::vector<std::string> serverHistory;
char *usedDir;
std::string usedDir;
};

#endif

+ 5
- 6
win/winvnc/ListConnInfo.h View File

@@ -21,8 +21,7 @@
#define __RFB_LISTCONNINFO_INCLUDED__

#include <list>

#include <rfb/util.h>
#include <string>

namespace winvnc {

@@ -53,12 +52,12 @@ namespace winvnc {

void addInfo(void* Conn, const char* IP, int Status) {
conn.push_back(Conn);
IP_address.push_back(rfb::strDup(IP));
IP_address.push_back(IP);
status.push_back(Status);
}

void iGetCharInfo(const char* buf[2]) {
buf[0] = *Ii;
buf[0] = Ii->c_str();
switch (*si) {
case 0:
buf[1] = "Full control";
@@ -107,10 +106,10 @@ namespace winvnc {

private:
std::list<void*> conn;
std::list<char*> IP_address;
std::list<std::string> IP_address;
std::list<int> status;
std::list<void*>::iterator ci;
std::list<char*>::iterator Ii;
std::list<std::string>::iterator Ii;
std::list<int>::iterator si;
bool disableClients;
};

Loading…
Cancel
Save