- if (errno == ENOENT)
- {
- if (mkdir (orig_dir, 0755) == -1)
- {
- char errbuf[1024];
- ERROR ("change_basedir: mkdir (%s): %s", orig_dir,
- sstrerror (errno, errbuf,
- sizeof (errbuf)));
- return (-1);
- }
- else if (chdir (orig_dir) == -1)
- {
- char errbuf[1024];
- ERROR ("chdir (%s): %s", orig_dir,
- sstrerror (errno, errbuf,
- sizeof (errbuf)));
- return (-1);
- }
- }
- else
- {
- char errbuf[1024];
- ERROR ("chdir (%s): %s", orig_dir,
- sstrerror (errno, errbuf,
- sizeof (errbuf)));
- return (-1);
- }
+ char errbuf[1024];
+ ERROR ("change_basedir: mkdir (%s): %s", dir,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ free (dir);
+ return (-1);
+ }
+
+ status = chdir (dir);
+ if (status != 0)
+ {
+ char errbuf[1024];
+ ERROR ("change_basedir: chdir (%s): %s", dir,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ free (dir);
+ return (-1);