126b76271a
Resolves: RHEL-58317 Resolves: RHEL-53438 Resolves: RHEL-36576 Resolves: RHEL-54006 Signed-off-by: Tao Liu <ltao@redhat.com>
112 lines
3.0 KiB
Diff
112 lines
3.0 KiB
Diff
From 6f9f9e9556db8d4ec5dc5f662a5fb13167dfa111 Mon Sep 17 00:00:00 2001
|
|
From: Rosen Penev <rosenp@gmail.com>
|
|
Date: Sun, 7 Jul 2024 18:02:12 -0700
|
|
Subject: [PATCH 36/44] avoid malloc with create_credentials_msg
|
|
|
|
Not really needed.
|
|
|
|
Signed-off-by: Rosen Penev <rosenp@gmail.com>
|
|
---
|
|
ui/irqbalance-ui.c | 39 ++++++++++++++++++++-------------------
|
|
ui/irqbalance-ui.h | 2 +-
|
|
2 files changed, 21 insertions(+), 20 deletions(-)
|
|
|
|
diff --git a/ui/irqbalance-ui.c b/ui/irqbalance-ui.c
|
|
index d281f47..f4cc48f 100644
|
|
--- a/ui/irqbalance-ui.c
|
|
+++ b/ui/irqbalance-ui.c
|
|
@@ -28,7 +28,7 @@ setup_t setup;
|
|
GMainLoop *main_loop;
|
|
static int default_bufsz = 8192;
|
|
|
|
-struct msghdr * create_credentials_msg(void)
|
|
+struct msghdr create_credentials_msg(void)
|
|
{
|
|
struct ucred credentials = {
|
|
.pid = getpid(),
|
|
@@ -36,12 +36,13 @@ struct msghdr * create_credentials_msg(void)
|
|
.gid = getegid(),
|
|
};
|
|
|
|
- struct msghdr *msg = g_malloc0(sizeof(struct msghdr));
|
|
- msg->msg_iovlen = 1;
|
|
- msg->msg_control = g_malloc(CMSG_SPACE(sizeof(struct ucred)));
|
|
- msg->msg_controllen = CMSG_SPACE(sizeof(struct ucred));
|
|
+ struct msghdr msg = {
|
|
+ .msg_iovlen = 1,
|
|
+ .msg_control = g_malloc(CMSG_SPACE(sizeof(struct ucred))),
|
|
+ .msg_controllen = CMSG_SPACE(sizeof(struct ucred)),
|
|
+ };
|
|
|
|
- struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg);
|
|
+ struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
|
|
cmsg->cmsg_level = SOL_SOCKET;
|
|
cmsg->cmsg_type = SCM_CREDENTIALS;
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct ucred));
|
|
@@ -90,16 +91,17 @@ void send_settings(char *data)
|
|
return;
|
|
}
|
|
|
|
- struct msghdr *msg = create_credentials_msg();
|
|
- struct iovec iov;
|
|
- iov.iov_base = (void *) data;
|
|
- iov.iov_len = strlen(data);
|
|
- msg->msg_iov = &iov;
|
|
- sendmsg(socket_fd, msg, 0);
|
|
+ struct iovec iov = {
|
|
+ .iov_base = (void *) data,
|
|
+ .iov_len = strlen(data),
|
|
+ };
|
|
+
|
|
+ struct msghdr msg = create_credentials_msg();
|
|
+ msg.msg_iov = &iov;
|
|
+ sendmsg(socket_fd, &msg, 0);
|
|
|
|
close(socket_fd);
|
|
- g_free(msg->msg_control);
|
|
- g_free(msg);
|
|
+ g_free(msg.msg_control);
|
|
}
|
|
|
|
char * get_data(char *string)
|
|
@@ -115,19 +117,18 @@ try_again:
|
|
return NULL;
|
|
}
|
|
|
|
- struct msghdr *msg = create_credentials_msg();
|
|
+ struct msghdr msg = create_credentials_msg();
|
|
struct iovec iov = {
|
|
.iov_base = (void *) string,
|
|
.iov_len = strlen(string),
|
|
};
|
|
- msg->msg_iov = &iov;
|
|
- sendmsg(socket_fd, msg, 0);
|
|
+ msg.msg_iov = &iov;
|
|
+ sendmsg(socket_fd, &msg, 0);
|
|
|
|
char *data = g_malloc(default_bufsz);
|
|
int len = recv(socket_fd, data, default_bufsz, MSG_TRUNC);
|
|
close(socket_fd);
|
|
- g_free(msg->msg_control);
|
|
- g_free(msg);
|
|
+ g_free(msg.msg_control);
|
|
if (len < 0) {
|
|
g_free(data);
|
|
return NULL;
|
|
diff --git a/ui/irqbalance-ui.h b/ui/irqbalance-ui.h
|
|
index 178be4b..4a2982d 100644
|
|
--- a/ui/irqbalance-ui.h
|
|
+++ b/ui/irqbalance-ui.h
|
|
@@ -72,7 +72,7 @@ typedef struct setup {
|
|
|
|
/* Function prototypes */
|
|
|
|
-struct msghdr * create_credentials_msg(void);
|
|
+struct msghdr create_credentials_msg(void);
|
|
int init_connection(void);
|
|
void send_settings(char *data);
|
|
char * get_data(char *string);
|
|
--
|
|
2.47.0
|
|
|