diff options
| author | YAMAMOTO Mitsuharu | 2018-09-07 08:35:36 +0900 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2018-09-07 08:35:36 +0900 |
| commit | 82160cf0c16e22bddfd90254e4a4e03ed383c9ae (patch) | |
| tree | ba169e84e296f5104a90ea9f6be84628b90ab331 /src/process.c | |
| parent | 6c616e465cc83cf376d4df75f9c4afdbdf0ef6ca (diff) | |
| download | emacs-82160cf0c16e22bddfd90254e4a4e03ed383c9ae.tar.gz emacs-82160cf0c16e22bddfd90254e4a4e03ed383c9ae.zip | |
* src/process.c (connect_network_socket): Fix memory leak. (Bug#32604)
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/process.c b/src/process.c index 676f38446e4..b0a327229c6 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -3321,11 +3321,9 @@ static void | |||
| 3321 | connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos, | 3321 | connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos, |
| 3322 | Lisp_Object use_external_socket_p) | 3322 | Lisp_Object use_external_socket_p) |
| 3323 | { | 3323 | { |
| 3324 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 3325 | int s = -1, outch, inch; | 3324 | int s = -1, outch, inch; |
| 3326 | int xerrno = 0; | 3325 | int xerrno = 0; |
| 3327 | int family; | 3326 | int family; |
| 3328 | struct sockaddr *sa = NULL; | ||
| 3329 | int ret; | 3327 | int ret; |
| 3330 | ptrdiff_t addrlen; | 3328 | ptrdiff_t addrlen; |
| 3331 | struct Lisp_Process *p = XPROCESS (proc); | 3329 | struct Lisp_Process *p = XPROCESS (proc); |
| @@ -3344,6 +3342,11 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos, | |||
| 3344 | /* Do this in case we never enter the while-loop below. */ | 3342 | /* Do this in case we never enter the while-loop below. */ |
| 3345 | s = -1; | 3343 | s = -1; |
| 3346 | 3344 | ||
| 3345 | struct sockaddr *sa = NULL; | ||
| 3346 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 3347 | record_unwind_protect_nothing (); | ||
| 3348 | ptrdiff_t count1 = SPECPDL_INDEX (); | ||
| 3349 | |||
| 3347 | while (!NILP (addrinfos)) | 3350 | while (!NILP (addrinfos)) |
| 3348 | { | 3351 | { |
| 3349 | Lisp_Object addrinfo = XCAR (addrinfos); | 3352 | Lisp_Object addrinfo = XCAR (addrinfos); |
| @@ -3356,9 +3359,8 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos, | |||
| 3356 | #endif | 3359 | #endif |
| 3357 | 3360 | ||
| 3358 | addrlen = get_lisp_to_sockaddr_size (ip_address, &family); | 3361 | addrlen = get_lisp_to_sockaddr_size (ip_address, &family); |
| 3359 | if (sa) | 3362 | sa = xrealloc (sa, addrlen); |
| 3360 | free (sa); | 3363 | set_unwind_protect_ptr (count, xfree, sa); |
| 3361 | sa = xmalloc (addrlen); | ||
| 3362 | conv_lisp_to_sockaddr (family, ip_address, sa, addrlen); | 3364 | conv_lisp_to_sockaddr (family, ip_address, sa, addrlen); |
| 3363 | 3365 | ||
| 3364 | s = socket_to_use; | 3366 | s = socket_to_use; |
| @@ -3520,7 +3522,7 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos, | |||
| 3520 | #endif /* !WINDOWSNT */ | 3522 | #endif /* !WINDOWSNT */ |
| 3521 | 3523 | ||
| 3522 | /* Discard the unwind protect closing S. */ | 3524 | /* Discard the unwind protect closing S. */ |
| 3523 | specpdl_ptr = specpdl + count; | 3525 | specpdl_ptr = specpdl + count1; |
| 3524 | emacs_close (s); | 3526 | emacs_close (s); |
| 3525 | s = -1; | 3527 | s = -1; |
| 3526 | if (0 <= socket_to_use) | 3528 | if (0 <= socket_to_use) |
| @@ -3591,6 +3593,7 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos, | |||
| 3591 | Lisp_Object data = get_file_errno_data (err, contact, xerrno); | 3593 | Lisp_Object data = get_file_errno_data (err, contact, xerrno); |
| 3592 | 3594 | ||
| 3593 | pset_status (p, list2 (Fcar (data), Fcdr (data))); | 3595 | pset_status (p, list2 (Fcar (data), Fcdr (data))); |
| 3596 | unbind_to (count, Qnil); | ||
| 3594 | return; | 3597 | return; |
| 3595 | } | 3598 | } |
| 3596 | 3599 | ||
| @@ -3610,7 +3613,7 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos, | |||
| 3610 | p->outfd = outch; | 3613 | p->outfd = outch; |
| 3611 | 3614 | ||
| 3612 | /* Discard the unwind protect for closing S, if any. */ | 3615 | /* Discard the unwind protect for closing S, if any. */ |
| 3613 | specpdl_ptr = specpdl + count; | 3616 | specpdl_ptr = specpdl + count1; |
| 3614 | 3617 | ||
| 3615 | if (p->is_server && p->socktype != SOCK_DGRAM) | 3618 | if (p->is_server && p->socktype != SOCK_DGRAM) |
| 3616 | pset_status (p, Qlisten); | 3619 | pset_status (p, Qlisten); |
| @@ -3671,6 +3674,7 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos, | |||
| 3671 | } | 3674 | } |
| 3672 | #endif | 3675 | #endif |
| 3673 | 3676 | ||
| 3677 | unbind_to (count, Qnil); | ||
| 3674 | } | 3678 | } |
| 3675 | 3679 | ||
| 3676 | /* Create a network stream/datagram client/server process. Treated | 3680 | /* Create a network stream/datagram client/server process. Treated |