Fix race condition in makedirs()

This commit is contained in:
Justine Tunney 2022-09-07 22:52:24 -07:00
parent b7c07d548c
commit 571c2c3c69
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
7 changed files with 90 additions and 10 deletions

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/x/x.h"
@ -24,5 +25,9 @@
* Returns base portion of path.
*/
char *xbasename(const char *path) {
return xstrdup(basename(gc(xstrdup(path))));
char *base;
path = xstrdup(path);
base = xstrdup(basename(path));
free(path);
return base;
}