I have this:
enum Units { Pounds, Kilos };
struct Configuration
{
const Units units;
const char *name;
inline Configuration(Units pUnits, char *pName) : units(pUnits)
{
name = strdup(pName);
}
inline ~Configuration() { free((void *)name); }
};
I was passing one of these to a method like this:
Configuration cc(Kilos, "abc");
cdao->write(cc);
I was getting nasty crashes from this until I tried redefining the method to take a reference:
Configuration cc(Kilos, "abc");
cdao->write(&cc);
And now everything works.
But how could the struct by value be screwing with memory?