Plan 9 from Bell Labs’s /usr/web/sources/patch/applied/pagefree/readme

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


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.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.