Hi, I'm trying to find the right way to free the returns from GetStatusEx. Using this demo module
I can turn a memory leak on and off with timewarp. But... all three ways leak, 328 bytes a pop on a 20-thruster DG.
So I can come up with a few explanations -- 1) I'm trying to free the wrong thing 2) there's some other right way to free that list, 3) it's getting freed, but Orbiter's leaking something else, 4) it's a runtime library mismatch of some sort (I'm using VCE2010).
If one of those ways should work, does the leak reproduce for anyone but me?
PHP:
#define ORBITER_MODULE
#define WIN32_LEAN_AND_MEAN
#include "Orbitersdk.h"
struct leak : public oapi::Module
{
char *lastp;
void clbkPreStep(double simt, double simdt, double mjd) {
if ( warp > 1.0 ) {
VESSELSTATUS2 st={2,VS_THRUSTLIST};pV->GetStatusEx(&st);
sprintf(oapiDebugString(),"%d %d", st.nthruster, (char*)st.thruster-lastp);
lastp=(char*)st.thruster;
if ( warp == 10.0 ) { if (st.thruster) free(st.thruster); }
else
if ( warp == 100.0 ) { if (st.thruster) delete st.thruster; }
else
if ( warp == 1000.0 ) { if (st.thruster) delete[] st.thruster; }
else
sprintf(oapiDebugString(),"oops");
}
}
void clbkFocusChanged (OBJHANDLE new_focus, OBJHANDLE old_focus) {
pV=oapiGetVesselInterface(new_focus);
}
void clbkTimeAccChanged (double new_warp, double old_warp) {
warp = new_warp;
}
double warp;
VESSEL *pV;
leak(HINSTANCE hModule) : oapi::Module(hModule), warp(1.0),pV(0), lastp(0) {}
};
DLLCLBK void InitModule(HINSTANCE hModule) { oapiRegisterModule(new leak(hModule)); return;}
DLLCLBK void ExitModule(HINSTANCE hModule) { return; }
I can turn a memory leak on and off with timewarp. But... all three ways leak, 328 bytes a pop on a 20-thruster DG.
So I can come up with a few explanations -- 1) I'm trying to free the wrong thing 2) there's some other right way to free that list, 3) it's getting freed, but Orbiter's leaking something else, 4) it's a runtime library mismatch of some sort (I'm using VCE2010).
If one of those ways should work, does the leak reproduce for anyone but me?