From 723828c4b88d65e53da8d18a148bdbc59222f5c7 Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Tue, 7 Jun 2016 18:09:37 +0200
Subject: [PATCH] =?UTF-8?q?plus=20de=20fuite=20de=20m=C3=A9moire,=20manque?=
=?UTF-8?q?=20plus=20qu'=C3=A0=20lire=20et=20push=20les=20messages?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/pubsubd.c | 30 +++++++++++++++++-------------
lib/pubsubd.h | 6 +++++-
pubsub/pubsubd.c | 1 +
3 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/lib/pubsubd.c b/lib/pubsubd.c
index 6021ed6..2554e9d 100644
--- a/lib/pubsubd.c
+++ b/lib/pubsubd.c
@@ -279,19 +279,13 @@ int pubsubd_get_new_process (struct service *srv, struct app_list_elm *ale
if (srv == NULL || ale == NULL || chans == NULL)
return -1;
- if (ale->p != NULL) {
- free (ale->p);
- ale->p = NULL;
- }
- ale->p = malloc (sizeof (struct process));
-
char *buf;
size_t msize;
srv_get_listen_raw (srv, &buf, &msize);
// parse pubsubd init msg (sent in TMPDIR/)
//
- // line fmt : pid index version chan action
+ // line fmt : pid index version action chan
// action : quit | pub | sub
size_t i;
@@ -314,11 +308,6 @@ int pubsubd_get_new_process (struct service *srv, struct app_list_elm *ale
case 2 : index = strtoul(token, NULL, 10); break;
case 3 : version = strtoul(token, NULL, 10); break;
case 4 : {
- memcpy (chan, token, (strlen (token) < BUFSIZ) ?
- strlen (token) : BUFSIZ);
- break;
- }
- case 5 : {
if (strncmp("both", token, 4) == 0) {
ale->action = PUBSUB_BOTH;
}
@@ -331,6 +320,13 @@ int pubsubd_get_new_process (struct service *srv, struct app_list_elm *ale
else { // everything else is about killing the service
ale->action = PUBSUB_QUIT;
}
+ break;
+ }
+ case 5 : {
+ if (ale->action != PUBSUB_QUIT)
+ memcpy (chan, token, (strlen (token) < BUFSIZ) ?
+ strlen (token) : BUFSIZ);
+ break;
}
}
}
@@ -355,7 +351,15 @@ int pubsubd_get_new_process (struct service *srv, struct app_list_elm *ale
}
pubsubd_channel_free (&c);
- srv_process_gen (ale->p, pid, index, version);
+ if (ale->p != NULL) {
+ free (ale->p);
+ ale->p = NULL;
+ }
+
+ if (ale->action != PUBSUB_QUIT) {
+ ale->p = malloc (sizeof (struct process));
+ srv_process_gen (ale->p, pid, index, version);
+ }
// add the subscriber
if (ale->action == PUBSUB_SUB || ale->action == PUBSUB_BOTH)
diff --git a/lib/pubsubd.h b/lib/pubsubd.h
index 8c1e015..ff5dc1f 100644
--- a/lib/pubsubd.h
+++ b/lib/pubsubd.h
@@ -26,6 +26,10 @@ void pubsubd_msg_serialize (const struct pubsub_msg *msg, char **data, size_t *l
void pubsubd_msg_unserialize (struct pubsub_msg *msg, const char *data, size_t len);
void pubsubd_msg_free (struct pubsub_msg *msg);
+// parse pubsubd init msg (sent in TMPDIR/)
+//
+// line fmt : pid index version action chan
+// action : quit | pub | sub
int pubsubd_get_new_process (struct service *srv, struct app_list_elm *ale
, struct channels *chans);
int pubsubd_msg_read_cb (FILE *f, char ** buf, size_t * msize);
@@ -68,7 +72,7 @@ void pubsubd_channels_del_all (struct channels *chans);
// head of the list
LIST_HEAD(app_list_head, app_list_elm);
-enum app_list_elm_action { PUBSUB_QUIT, PUBSUB_PUB, PUBSUB_SUB, PUBSUB_BOTH };
+enum app_list_elm_action {PUBSUB_QUIT = 1, PUBSUB_PUB, PUBSUB_SUB, PUBSUB_BOTH};
// element of the list
struct app_list_elm {
diff --git a/pubsub/pubsubd.c b/pubsub/pubsubd.c
index 86f44d1..329c51b 100644
--- a/pubsub/pubsubd.c
+++ b/pubsub/pubsubd.c
@@ -37,6 +37,7 @@ main(int argc, char* argv[])
printf ("Quitting ...\n");
pubsubd_channels_del_all (&chans);
+ // pubsubd_app_list_elm_free (&ale);
srv_close (&srv);
// TODO end the threads