[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r111919: * filelock.c (lock_file): Do
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r111919: * filelock.c (lock_file): Don't access freed storage. |
Date: |
Sat, 02 Mar 2013 13:05:52 -0800 |
User-agent: |
Bazaar (2.5.0) |
------------------------------------------------------------
revno: 111919
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Sat 2013-03-02 13:05:52 -0800
message:
* filelock.c (lock_file): Don't access freed storage.
modified:
src/ChangeLog
src/filelock.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2013-03-02 20:41:53 +0000
+++ b/src/ChangeLog 2013-03-02 21:05:52 +0000
@@ -27,6 +27,7 @@
that's not portable.
(lock_file): Document that this function can return if lock
creation fails.
+ (lock_file): Don't access freed storage.
2013-03-02 Andreas Schwab <address@hidden>
=== modified file 'src/filelock.c'
--- a/src/filelock.c 2013-03-02 20:41:53 +0000
+++ b/src/filelock.c 2013-03-02 21:05:52 +0000
@@ -597,11 +597,9 @@
void
lock_file (Lisp_Object fn)
{
- register Lisp_Object attack, orig_fn, encoded_fn;
- register char *lfname, *locker;
- ptrdiff_t locker_size;
+ Lisp_Object orig_fn, encoded_fn;
+ char *lfname;
lock_info_type lock_info;
- printmax_t pid;
struct gcpro gcpro1;
USE_SAFE_ALLOCA;
@@ -642,32 +640,29 @@
call1 (intern ("ask-user-about-supersession-threat"), fn);
}
+
+ /* Try to lock the lock. */
+ if (0 < lock_if_free (&lock_info, lfname))
+ {
+ /* Someone else has the lock. Consider breaking it. */
+ ptrdiff_t locker_size = (strlen (lock_info.user) + strlen
(lock_info.host)
+ + INT_STRLEN_BOUND (printmax_t)
+ + sizeof "@ (pid )");
+ char *locker = SAFE_ALLOCA (locker_size);
+ printmax_t pid = lock_info.pid;
+ Lisp_Object attack;
+ esprintf (locker, "address@hidden (pid %"pMd")",
+ lock_info.user, lock_info.host, pid);
+ FREE_LOCK_INFO (lock_info);
+
+ attack = call2 (intern ("ask-user-about-lock"), fn, build_string
(locker));
+ /* Take the lock if the user said so. */
+ if (!NILP (attack))
+ lock_file_1 (lfname, 1);
+ }
+
UNGCPRO;
-
- /* Try to lock the lock. */
- if (lock_if_free (&lock_info, lfname) <= 0)
- /* Return now if we have locked it, or if lock creation failed */
- return;
-
- /* Else consider breaking the lock */
- locker_size = (strlen (lock_info.user) + strlen (lock_info.host)
- + INT_STRLEN_BOUND (printmax_t)
- + sizeof "@ (pid )");
- locker = SAFE_ALLOCA (locker_size);
- pid = lock_info.pid;
- esprintf (locker, "address@hidden (pid %"pMd")",
- lock_info.user, lock_info.host, pid);
- FREE_LOCK_INFO (lock_info);
-
- attack = call2 (intern ("ask-user-about-lock"), fn, build_string (locker));
SAFE_FREE ();
- if (!NILP (attack))
- /* User says take the lock */
- {
- lock_file_1 (lfname, 1);
- return;
- }
- /* User says ignore the lock */
}
void
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r111919: * filelock.c (lock_file): Don't access freed storage.,
Paul Eggert <=