This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFAv2] Fix leak in displaced step.


On Mon, 2018-11-12 at 16:17 +0000, Simon Marchi wrote:
> From what I understand, the allocation model you propose in this patch is to
> allocate a buffer the first time we do a displaced step for an inferior and
> free it when the inferior exits.
Yes, that is the plan.

>   The allocated size is
> 
>   len = gdbarch_max_insn_length (gdbarch);
> 
> Given that there can be multiple architectures inside a single inferior, can
> the required buffer size change between multiple displaced step?
Good remark : I did not know of this multiple architecture for a
single inferior, and then yes possibly the buffer might have to change size.
So, we should rather do (unconditionally) :
  displaced->step_saved_copy = (gdb_byte *) xrealloc (len);

> 
> Also, if freeing the buffer on inferior exit is indeed what we want to do, why do
> we need the above cleanup?  Even if the setup fails, shouldn't be fine to keep the buffer
> allocated?
The idea was to avoid having a piece of memory containing not properly 
initialized data. But probably this is not a problem, as this data will
only be used if the displaced setup is finished, at the end of the function.
So, effectively no real need for the cleanup anymore.

Philippe


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]