[PATCH] multipathd: fix memory allocation logic error for polls in uxsock_listen()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "tang.junhui" <tang.junhui@xxxxxxxxxx>

logic error exists in memory allocation for polls in uxsock_listen(), even if the allocated memory size meet the needs, it is still to realloc memory, which is not up to expectations.

Signed-off-by: tang.junhui <tang.junhui@xxxxxxxxxx>
---
 multipathd/uxlsnr.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
index f114e59..fa29b2a 100644
--- a/multipathd/uxlsnr.c
+++ b/multipathd/uxlsnr.c
@@ -145,7 +145,7 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, void * trigger_data)
 	pthread_cleanup_push(uxsock_cleanup, NULL);
 
 	condlog(3, "uxsock: startup listener");
-	polls = (struct pollfd *)MALLOC(MIN_POLLS + 1);
+	polls = (struct pollfd *)MALLOC((MIN_POLLS + 1) * sizeof(struct pollfd));
 	if (!polls) {
 		condlog(0, "uxsock: failed to allocate poll fds");
 		return NULL;
@@ -167,9 +167,11 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, void * trigger_data)
 		}
 		if (num_clients != old_clients) {
 			struct pollfd *new;
-			if (num_clients < MIN_POLLS) {
+			if (num_clients <= MIN_POLLS && old_clients > MIN_POLLS) {
 				new = REALLOC(polls, (1 + MIN_POLLS) *
 						sizeof(struct pollfd));
+			} else if (num_clients <= MIN_POLLS && old_clients <= MIN_POLLS) {
+				new = polls;
 			} else {
 				new = REALLOC(polls, (1+num_clients) *
 						sizeof(struct pollfd));
@@ -181,7 +183,7 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, void * trigger_data)
 				pthread_yield();
 				continue;
 			}
-			num_clients = old_clients;
+			old_clients = num_clients;
 			polls = new;
 		}
 		polls[0].fd = ux_sock;
-- 
2.8.1.windows.1

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel



[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux