[patch] applied: pagefree

0 views
Skip to first unread message

9cha...@cat-v.org

unread,
Apr 16, 2008, 1:26:58 PM4/16/08
to plan9c...@googlegroups.com
Created Apr 16 11:26 by none
Processed Apr 16 17:26 by geoff

I came across the following code in /sys/src/cmd/page/view.c:

srvfd = open(srv, ORDWR);
free(srv);
if(srvfd == -1){
fprint(2, "page: can't open %s: %r\n", srv);
wexits("no srv");
}

Notice that srv is used after being freed when open(2) fails.

This patch simply moves the call to free(2) after the if statement. Wexits kills the program so no memory should be leaked by that branch.

--
/sys/src/cmd/page/view.c
view.c.orig:988,998 - /n/sources/patch/applied/pagefree/view.c:988,998
}else
pid = getpid();
srvfd = open(srv, ORDWR);
- free(srv);
if(srvfd == -1){
fprint(2, "page: can't open %s: %r\n", srv);
wexits("no srv");
}
+ free(srv);
sprint(spec, "new -pid %d", pid);
if(mount(srvfd, -1, "/mnt/wsys", 0, spec) == -1){
fprint(2, "page: can't mount /mnt/wsys: %r (spec=%s)\n", spec);

Reply all
Reply to author
Forward
0 new messages