I'm having one of those moments where I'm sure there is some obvious thing I'm missing but I can't see it for looking.
We have some code (Not Invented Here, natch) which looks something like this (I've made it pseudocode for ease of reading):
struct outputs_struct{
char *SomeString;
};
int DoSomething(struct allthings_struct *AllThings)
{
struct inputs_struct The_Inputs;
struct outputs_struct The_Outputs;
int error = 0;
// Populate input data, then:
error = DoGetOutputsFromInputs(Allthings, &The_Inputs, &The_Outputs);
return error;
}
int DoGetOutputsFromInputs(struct allthings_struct *AllThings, struct input_struct *Inputs, struct outputs_struct *Outputs)
{
// Some reading of input data, then:
Outputs->SomeString = (char *)malloc(100);
strcpy(Outputs->SomeString, "Hello,world");
// Some other stuff
return 0;
}
As soon as this function returns, we get a SEGFAULT.
It SEGFAULTs immediately on coming back from DoGetOutputsFromInputs(). Likewise if I print markers & pause before the return statement in DoGetOutputsFromInputs() it is fine right up to the moment it actually returns.
I have also tried upping my caffeine dosage, experiments are ongoing in that department, so far: no progress.
Edit 1: Further testing reveals it's not the malloc() that's at fault / causing the issue, the code actually crashes if we return sooner than that part, so I think there is some oddness going on elsewhere that I will have to chase down.
Apologies for the vagueness and pseudocode, it's a huge steaming pile of code auto-generated by gSoap (which doesn't auto-generate any sort of comments or documentation, of course...) from ONVIF WSDL's, we're developing in Ubuntu and the target is a TI DaVinci DSP/ARM9 SoC. This code is a subsection of a corner of the TI SDK and hence various things are outside our immediate influence / too time-consuming to delve into.