[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [RFC 3/6] Introduce _xrealloc
On Thu, 8 Jun 2017, Sameer Goel wrote: > Introduce a memory realloc function. > > Signed-off-by: Sameer Goel <sgoel@xxxxxxxxxxxxxx> > --- > xen/common/xmalloc_tlsf.c | 13 +++++++++++++ > xen/include/xen/xmalloc.h | 1 + > 2 files changed, 14 insertions(+) > > diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c > index b256dc5..52385a8 100644 > --- a/xen/common/xmalloc_tlsf.c > +++ b/xen/common/xmalloc_tlsf.c > @@ -612,6 +612,19 @@ void *_xzalloc(unsigned long size, unsigned long align) > return p ? memset(p, 0, size) : p; > } > > +void *_xrealloc(void *p, unsigned long new_size, unsigned long align) > +{ > + void *new_p = _xmalloc(new_size, align); It might be best to handle the case where new_size is 0 explicitly, and only free p. > + if(new_p && p) > + { > + memcpy(new_p, p, new_size); > + xfree(p); > + } > + > + return new_p; > +} > + > void xfree(void *p) > { > struct bhdr *b; > diff --git a/xen/include/xen/xmalloc.h b/xen/include/xen/xmalloc.h > index 24a99ac..41a9b2f 100644 > --- a/xen/include/xen/xmalloc.h > +++ b/xen/include/xen/xmalloc.h > @@ -29,6 +29,7 @@ extern void xfree(void *); > /* Underlying functions */ > extern void *_xmalloc(unsigned long size, unsigned long align); > extern void *_xzalloc(unsigned long size, unsigned long align); > +extern void *_xrealloc(void *p, unsigned long new_size, unsigned long align); > > static inline void *_xmalloc_array( > unsigned long size, unsigned long align, unsigned long num) > -- > Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, > Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a > Linux Foundation Collaborative Project. > _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |