[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] tools/xenpaging: fix bug of Segmentation fault
Great catch, thanks! Just a couple minor nitpicks, if this patch hasn't been applied yet. For the line: + Â Âint rc = -1, rc1; could this instead be: + int rc = -1; + int rc1; And for: + Â Âif ( argc != 3 ) { would it be possible to move the { down onto it's own line? These changes would make it fit in with the rest of the source better. Thanks, Patrick On 10 February 2010 21:57, Yu Zhiguo <yuzg@xxxxxxxxxxxxxx> wrote: > Segmentation fault occurs in two situations: > 1. argc is less than 3 > 2. xenpaging_init() fault > > Signed-off-by: Yu Zhiguo <yuzg@xxxxxxxxxxxxxx> > > diff --git a/tools/xenpaging/xenpaging.c b/tools/xenpaging/xenpaging.c > --- a/tools/xenpaging/xenpaging.c > +++ b/tools/xenpaging/xenpaging.c > @@ -212,6 +212,9 @@ > Â{ > Â Â int rc; > > + Â Âif ( paging == NULL ) > + Â Â Â Âreturn 0; > + > Â Â /* Tear down domain paging in Xen */ > Â Â rc = xc_mem_event_disable(paging->xc_handle, paging->mem_event.domain_id); > Â Â if ( rc != 0 ) > @@ -447,20 +450,29 @@ > > Âint main(int argc, char *argv[]) > Â{ > - Â Âdomid_t domain_id = atoi(argv[1]); > - Â Âint num_pages = atoi(argv[2]); > + Â Âdomid_t domain_id; > + Â Âint num_pages; > Â Â xenpaging_t *paging; > - Â Âxenpaging_victim_t victims[num_pages]; > + Â Âxenpaging_victim_t *victims; > Â Â mem_event_request_t req; > Â Â mem_event_response_t rsp; > Â Â int i; > - Â Âint rc; > + Â Âint rc = -1, rc1; > > Â Â int open_flags = O_CREAT | O_TRUNC | O_RDWR; > Â Â mode_t open_mode = S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | > S_IWOTH; > Â Â char filename[80]; > Â Â int fd; > > + Â Âif ( argc != 3 ) { > + Â Â Â Âfprintf(stderr, "Usage: %s <domain_id> <num_pages>\n", argv[0]); > + Â Â Â return -1; > + Â Â} > + Â Âdomain_id = atoi(argv[1]); > + Â Ânum_pages = atoi(argv[2]); > + > + Â Âvictims = calloc(num_pages, sizeof(xenpaging_victim_t)); > + > Â Â /* Open file */ > Â Â sprintf(filename, "page_cache_%d", domain_id); > Â Â fd = open(filename, open_flags, open_mode); > @@ -586,15 +598,17 @@ > Â Â } > > Âout: > + Â Âfree(victims); > + > Â Â /* Tear down domain paging */ > - Â Ârc = xenpaging_teardown(paging); > - Â Âif ( rc != 0 ) > - Â Â{ > + Â Ârc1 = xenpaging_teardown(paging); > + Â Âif ( rc1 != 0 ) > Â Â Â Â ERROR("Error tearing down paging"); > - Â Â Â Âexit(1); > - Â Â} > > - Â Âreturn 0; > + Â Âif ( rc == 0 ) > + Â Â Â Ârc = rc1; > + > + Â Âreturn rc; > Â} > > > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@xxxxxxxxxxxxxxxxxxx > http://lists.xensource.com/xen-devel > > _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |