On Wed, 2015-12-09 at 12:56 +0000, Wei Liu wrote:
> On Wed, Dec 09, 2015 at 12:41:49PM +0000, Ian Campbell wrote:
> > On Wed, 2015-12-09 at 12:22 +0000, Wei Liu wrote:
> > > > diff --git a/tools/libs/foreignmemory/core.c
> > > > b/tools/libs/foreignmemory/core.c
> > > > index 21dc7ee..91bea55 100644
> > > > --- a/tools/libs/foreignmemory/core.c
> > > > +++ b/tools/libs/foreignmemory/core.c
> > > > @@ -14,6 +14,8 @@
> > > >   */
> > > >  
> > > >  #include <stdlib.h>
> > > > +#include <assert.h>
> > > > +#include <errno.h>
> > > >  
> > > >  #include "private.h"
> > > >  
> > > > @@ -64,7 +66,33 @@ void
> > > > *xenforeignmemory_map(xenforeignmemory_handle
> > > > *fmem,
> > > >                             uint32_t dom, int prot,
> > > >                             const xen_pfn_t *arr, int *err, size_t
> > > > num)
> > > >  {
> > > > -    return osdep_xenforeignmemory_map(fmem, dom, prot, arr, err,
> > > > num);
> > > > +    void *ret;
> > > > +    int *err_to_free = NULL;
> > > > +
> > > > +    if ( err == NULL )
> > > > +        err = err_to_free = malloc(num * sizeof(int));
> > > > +
> > > 
> > > malloc can fail, which means when user passes in err==NULL there is
> > > two
> > > possible behaviours of this function?
> > 
> > Partially/Full success and "fail entirely reporting an error" you mean?
> > There are always those two possibilities, yes, regardless of err==NULL.
> > I
> > think that's inline with the doc comment too.
> > 
> > If that's not what you were asking then I'm afraid I don't see what you
> > are
> > getting at.
> > 
> 
> What I meant was we should check err != NULL after malloc because
> osdep_xenforeignmeory_map dereferences it unconditionally.

Ah, I appear to have managed to put that check in
"tools/libs/foreignmemory: optimise map(num==1, err==NULL) case" by
mistake, so I was confused because I was looking at the final version of
the file.

I shall move it, thanks.

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

Reply via email to