1
0
Fork 0

Fix mismatched new/strdup/delete[] froub by ASan

See: https://sourceforge.net/p/flightgear/codetickets/2367/ for the
issue. Switch to using std::string instead of char*, and hence any
need to manually free the memory.
This commit is contained in:
James Turner 2020-09-04 12:41:56 +01:00
parent 4402d7b81d
commit d2fb16e071
2 changed files with 5 additions and 7 deletions

View file

@ -47,14 +47,12 @@ FGFDM::~FGFDM()
{
for(int i=0; i<_thrusters.size(); i++) {
EngRec* er = (EngRec*)_thrusters.get(i);
delete[] er->prefix;
delete er->eng;
delete er;
}
for(int i=0; i<_weights.size(); i++) {
WeightRec* wr = (WeightRec*)_weights.get(i);
delete[] wr->prop;
delete wr;
}
@ -365,7 +363,7 @@ void FGFDM::getExternalInput(float dt)
if(t->getPropEngine()) {
PropEngine* p = t->getPropEngine();
sprintf(buf, "%s/rpm", er->prefix);
sprintf(buf, "%s/rpm", er->prefix.c_str());
p->setOmega(fgGetFloat(buf, 500) * RPM2RAD);
}
}
@ -373,7 +371,7 @@ void FGFDM::getExternalInput(float dt)
// Linearly "seeks" a property by the specified fraction of the way to
// the target value. Used to emulate "slowly changing" output values.
static void moveprop(SGPropertyNode* node, const char* prop,
static void moveprop(SGPropertyNode* node, const std::string& prop,
float target, float frac)
{
float val = node->getFloatValue(prop);
@ -1135,7 +1133,7 @@ void FGFDM::parseWeight(const XMLAttributes* a)
float v[3];
attrf_xyz(a, v);
wr->prop = strdup(a->getValue("mass-prop"));
wr->prop = std::string{a->getValue("mass-prop")};
wr->size = attrf(a, "size", 0);
wr->handle = _airplane.addWeight(v, wr->size);
_weights.add(wr);

View file

@ -32,11 +32,11 @@ public:
private:
struct EngRec {
char* prefix {nullptr};
std::string prefix;
Thruster* eng {nullptr};
};
struct WeightRec {
char* prop {nullptr};
std::string prop;
float size {0};
int handle {0};
};