You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2022/07/23 19:58:14 UTC
[incubator-nuttx-apps] 11/20: app/system/uorb: alloc on heap instead of stack.
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 384c05beb27e63d2517caa70f0279237084e4fe2
Author: jihandong <ji...@xiaomi.com>
AuthorDate: Sat May 7 22:30:47 2022 +0800
app/system/uorb: alloc on heap instead of stack.
Signed-off-by: jihandong <ji...@xiaomi.com>
---
system/uorb/listener.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/system/uorb/listener.c b/system/uorb/listener.c
index 8369503b5..0abe69c73 100644
--- a/system/uorb/listener.c
+++ b/system/uorb/listener.c
@@ -492,13 +492,26 @@ static int listener_print(FAR const struct orb_metadata *meta, int fd)
static void listener_monitor(FAR struct list_node *objlist, int nb_objects,
int topic_rate, int nb_msgs, int timeout)
{
- struct pollfd fds[nb_objects];
- int recv_msgs[nb_objects];
+ FAR struct pollfd *fds;
+ FAR int *recv_msgs;
int nb_recv_msgs = 0;
int i = 0;
struct listen_object_s *tmp;
+ fds = malloc(nb_objects * sizeof(struct pollfd));
+ if (!fds)
+ {
+ return;
+ }
+
+ recv_msgs = malloc(nb_objects * sizeof(int));
+ if (!recv_msgs)
+ {
+ free(fds);
+ return;
+ }
+
/* Prepare pollfd for all objects */
list_for_every_entry(objlist, tmp, struct listen_object_s, node)
@@ -533,6 +546,8 @@ static void listener_monitor(FAR struct list_node *objlist, int nb_objects,
if (nb_msgs == 1)
{
+ free(fds);
+ free(recv_msgs);
return;
}
@@ -594,6 +609,8 @@ static void listener_monitor(FAR struct list_node *objlist, int nb_objects,
uorbinfo_raw("Total number of received Message:%d/%d",
nb_recv_msgs, nb_msgs ? nb_msgs : nb_recv_msgs);
+ free(fds);
+ free(recv_msgs);
}
/****************************************************************************