]> git.saurik.com Git - cycript.git/commitdiff
Do not leave console socket lying around in /tmp.
authorJay Freeman (saurik) <saurik@saurik.com>
Tue, 11 Mar 2014 22:44:54 +0000 (15:44 -0700)
committerJay Freeman (saurik) <saurik@saurik.com>
Tue, 11 Mar 2014 22:49:48 +0000 (15:49 -0700)
Console.cpp

index f93e090784629ccc10a3868e979cc8fcc559e353..945b9bcfcac964e4ec71e4ff21061393c4397ffd 100644 (file)
@@ -814,19 +814,27 @@ int Main(int argc, char const * const argv[], char const * const envp[]) {
             address.sun_family = AF_UNIX;
 
             sprintf(address.sun_path, "/tmp/.s.cy.%u", getpid());
+            unlink(address.sun_path);
+
+            struct File {
+                const char *path_;
+
+                File(const char *path) :
+                    path_(path)
+                {
+                }
+
+                ~File() {
+                    unlink(path_);
+                }
+            } file(address.sun_path);
 
             _syscall(bind(server, reinterpret_cast<sockaddr *>(&address), SUN_LEN(&address)));
             _syscall(chmod(address.sun_path, 0777));
 
-            try {
-                _syscall(listen(server, 1));
-                InjectLibrary(pid);
-                client_ = _syscall(accept(server, NULL, NULL));
-            } catch (...) {
-                // XXX: exception?
-                unlink(address.sun_path);
-                throw;
-            }
+            _syscall(listen(server, 1));
+            InjectLibrary(pid);
+            client_ = _syscall(accept(server, NULL, NULL));
         } catch (...) {
             _syscall(close(server));
             throw;