[PATCH 0/9] Trivial cleanups

5 views
Skip to first unread message

Felipe Contreras

unread,
Feb 7, 2010, 6:30:41 PM2/7/10
to msn-...@googlegroups.com, Felipe Contreras
Hi,

Here are a bunch of trivial cleanups; no important changes.

Felipe Contreras (9):
build: reorganize CFLAGS
Plug a few mem leaks
ns: accept NULL in _destroy()
log: make PECAN_LOG_LEVEL public
msg: improve show_readable()
Trivial cleanups
io: trivial cleaups for g_object_unref
io: trivial parent class cleanups
peer-link: be more verbose with unprocessed msgs

Makefile | 16 ++++++++--------
cmd/msg.c | 5 +++++
cvr/pn_direct_conn.c | 5 +++++
cvr/pn_peer_link.c | 6 ++++--
io/pn_cmd_server.c | 6 +++---
io/pn_dc_conn.c | 6 +++---
io/pn_http_server.c | 13 ++++++-------
io/pn_node.c | 8 ++++----
io/pn_ssl_conn.c | 14 +++-----------
msn.c | 3 ---
notification.c | 3 +++
pn_log.c | 6 ------
pn_log.h | 6 ++++++
session.c | 3 +--
switchboard.c | 2 ++
15 files changed, 53 insertions(+), 49 deletions(-)

Felipe Contreras

unread,
Feb 7, 2010, 6:30:42 PM2/7/10
to msn-...@googlegroups.com, Felipe Contreras
These we want to override.

Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
Makefile | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 50e64d9..0c01c09 100644
--- a/Makefile
+++ b/Makefile
@@ -25,14 +25,6 @@ DIRECTCONN := y

CFLAGS := -O2

-ifdef DEBUG
- CFLAGS += -ggdb
-endif
-
-ifdef DEVEL
- CFLAGS += -DPECAN_DEVEL
-endif
-
EXTRA_WARNINGS := -Wall -Wextra -Wformat-nonliteral -Wcast-align -Wpointer-arith \
-Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes \
-Wmissing-declarations -Winline -Wundef -Wnested-externs -Wcast-qual \
@@ -45,6 +37,14 @@ OTHER_WARNINGS := -D_FORTIFY_SOURCE=2 -fstack-protector -g3 -Wdisabled-optimizat

CFLAGS += -Wall # $(EXTRA_WARNINGS)

+ifdef DEBUG
+ override CFLAGS += -ggdb
+endif
+
+ifdef DEVEL
+ override CFLAGS += -DPECAN_DEVEL
+endif
+
override CFLAGS += -D_XOPEN_SOURCE
override CFLAGS += -I. -DENABLE_NLS -DHAVE_LIBPURPLE -DPURPLE_DEBUG

--
1.6.6.1

Felipe Contreras

unread,
Feb 7, 2010, 6:30:43 PM2/7/10
to msn-...@googlegroups.com, Felipe Contreras
Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
cvr/pn_direct_conn.c | 5 +++++
cvr/pn_peer_link.c | 2 ++
switchboard.c | 2 ++
3 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/cvr/pn_direct_conn.c b/cvr/pn_direct_conn.c
index 35ca6e4..ef6e3d9 100644
--- a/cvr/pn_direct_conn.c
+++ b/cvr/pn_direct_conn.c
@@ -266,6 +266,11 @@ pn_direct_conn_destroy(struct pn_direct_conn *direct_conn)
{
pn_log ("begin");

+ {
+ char *addr;
+ while ((addr = g_queue_pop_head(direct_conn->addrs)))
+ g_free(addr);
+ }
g_queue_free(direct_conn->addrs);

if (direct_conn->last_msg)
diff --git a/cvr/pn_peer_link.c b/cvr/pn_peer_link.c
index 1371eb4..039d3ce 100644
--- a/cvr/pn_peer_link.c
+++ b/cvr/pn_peer_link.c
@@ -108,6 +108,8 @@ pn_peer_link_free(struct pn_peer_link *link)
pn_direct_conn_destroy(link->direct_conn);
#endif /* MSN_DIRECTCONN */

+ g_queue_free(link->slp_msg_queue);
+
g_free(link->local_user);
g_free(link->remote_user);

diff --git a/switchboard.c b/switchboard.c
index 71166a6..74a36f3 100644
--- a/switchboard.c
+++ b/switchboard.c
@@ -267,6 +267,8 @@ msn_switchboard_free (MsnSwitchBoard *swboard)
for (l = swboard->users; l; l = l->next)
g_free(l->data);

+ g_list_free(swboard->users);
+
if (swboard->cmdproc)
swboard->cmdproc->data = NULL;

--
1.6.6.1

Felipe Contreras

unread,
Feb 7, 2010, 6:30:44 PM2/7/10
to msn-...@googlegroups.com, Felipe Contreras
Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
notification.c | 3 +++
session.c | 3 +--
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/notification.c b/notification.c
index dce9d68..a01cefc 100644
--- a/notification.c
+++ b/notification.c
@@ -201,6 +201,9 @@ msn_notification_new(MsnSession *session)
void
msn_notification_destroy(MsnNotification *notification)
{
+ if (!notification)
+ return;
+
if (notification->cmdproc)
notification->cmdproc->data = NULL;

diff --git a/session.c b/session.c
index 6d44f17..367c341 100644
--- a/session.c
+++ b/session.c
@@ -142,8 +142,7 @@ msn_session_destroy (MsnSession *session)
g_hash_table_destroy (session->links);
#endif /* defined(PECAN_CVR) */

- if (session->notification)
- msn_notification_destroy (session->notification);
+ msn_notification_destroy (session->notification);

pn_dp_manager_free (session->dp_manager);

--
1.6.6.1

Felipe Contreras

unread,
Feb 7, 2010, 6:30:45 PM2/7/10
to msn-...@googlegroups.com, Felipe Contreras
Will be useful for other code.

Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---

pn_log.c | 6 ------
pn_log.h | 6 ++++++

2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/pn_log.c b/pn_log.c
index 127536e..6317e6a 100644
--- a/pn_log.c
+++ b/pn_log.c
@@ -34,12 +34,6 @@
#include <debug.h>
#endif /* PURPLE_DEBUG */

-#ifdef PECAN_DEVEL
-#define PECAN_LOG_LEVEL PN_LOG_LEVEL_LOG
-#else
-#define PECAN_LOG_LEVEL PN_LOG_LEVEL_INFO
-#endif
-
static inline const gchar *
log_level_to_string (PecanLogLevel level)
{
diff --git a/pn_log.h b/pn_log.h
index c42d091..70bc1aa 100644
--- a/pn_log.h
+++ b/pn_log.h
@@ -49,6 +49,12 @@ enum PecanLogLevel
PN_LOG_LEVEL_TEST,
};

+#ifdef PECAN_DEVEL
+#define PECAN_LOG_LEVEL PN_LOG_LEVEL_LOG
+#else
+#define PECAN_LOG_LEVEL PN_LOG_LEVEL_INFO
+#endif
+
typedef enum PecanLogLevel PecanLogLevel;

void pn_base_log_helper (PecanLogLevel level,
--
1.6.6.1

Felipe Contreras

unread,
Feb 7, 2010, 6:30:46 PM2/7/10
to msn-...@googlegroups.com, Felipe Contreras
So that we don't waste resources when nothing is printed.

Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---

cmd/msg.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/cmd/msg.c b/cmd/msg.c
index 963f408..62e26d7 100644
--- a/cmd/msg.c
+++ b/cmd/msg.c
@@ -710,6 +710,7 @@ void
msn_message_show_readable(MsnMessage *msg, const char *info,
gboolean text_body)
{
+#if defined(PN_DEBUG)
GString *str;
size_t body_len;
const char *body;
@@ -717,6 +718,9 @@ msn_message_show_readable(MsnMessage *msg, const char *info,

g_return_if_fail(msg != NULL);

+ if (PECAN_LOG_LEVEL < PN_LOG_LEVEL_DEBUG)
+ return;
+
str = g_string_new(NULL);

/* Standard header. */
@@ -803,4 +807,5 @@ msn_message_show_readable(MsnMessage *msg, const char *info,
pn_debug ("info=[%s],str=[%s]", info, str->str);

g_string_free(str, TRUE);
+#endif /* PN_DEBUG */
}
--
1.6.6.1

Felipe Contreras

unread,
Feb 7, 2010, 6:30:47 PM2/7/10
to msn-...@googlegroups.com, Felipe Contreras
No functional changes.

Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---

io/pn_http_server.c | 1 -
io/pn_ssl_conn.c | 10 +---------
msn.c | 3 ---
3 files changed, 1 insertions(+), 13 deletions(-)

diff --git a/io/pn_http_server.c b/io/pn_http_server.c
index 25770ab..a7c89b3 100644
--- a/io/pn_http_server.c
+++ b/io/pn_http_server.c
@@ -486,7 +486,6 @@ connect_impl (PnNode *conn,
conn->connect_data = purple_proxy_connect (NULL, msn_session_get_user_data (conn->session),
hostname, port, connect_cb, conn);
#endif
- return;
}
else
{
diff --git a/io/pn_ssl_conn.c b/io/pn_ssl_conn.c
index 15ddbbe..6237780 100644
--- a/io/pn_ssl_conn.c
+++ b/io/pn_ssl_conn.c
@@ -168,7 +168,7 @@ connect_cb (gpointer data,
{
conn->open = TRUE;

- pn_info ("connected: conn=%p,ssl_conn=%p", conn, ssl_conn);
+ pn_info ("connected: conn=%p", conn);
purple_ssl_input_add (gsc, read_cb, conn);
}
else
@@ -261,14 +261,6 @@ close_impl (PnNode *conn)
}

#ifdef HAVE_LIBPURPLE
-#if 0
- if (ssl_conn->read_watch)
- {
- purple_input_remove (ssl_conn->read_watch);
- ssl_conn->read_watch = 0;
- }
-#endif
-
if (ssl_conn->ssl_data)
{
pn_info ("ssl shutdown: %p", ssl_conn->ssl_data);
diff --git a/msn.c b/msn.c
index 99ec39e..ec94143 100644
--- a/msn.c
+++ b/msn.c
@@ -1533,7 +1533,6 @@ chat_leave (PurpleConnection *gc,
{
MsnSession *session;
MsnSwitchBoard *swboard;
- PurpleConversation *conv;

session = gc->proto_data;

@@ -1543,8 +1542,6 @@ chat_leave (PurpleConnection *gc,
if (!swboard)
return;

- conv = swboard->conv;
-
g_hash_table_remove (session->chats, GINT_TO_POINTER (id));
swboard->conv = NULL;
}
--
1.6.6.1

Felipe Contreras

unread,
Feb 7, 2010, 6:30:48 PM2/7/10
to msn-...@googlegroups.com, Felipe Contreras
It receives a void *; no need to cast.

Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---

io/pn_cmd_server.c | 2 +-
io/pn_dc_conn.c | 2 +-
io/pn_http_server.c | 8 ++++----
io/pn_node.c | 2 +-
io/pn_ssl_conn.c | 2 +-
5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/io/pn_cmd_server.c b/io/pn_cmd_server.c
index 00d25cc..acd11b0 100644
--- a/io/pn_cmd_server.c
+++ b/io/pn_cmd_server.c
@@ -66,7 +66,7 @@ void
pn_cmd_server_free (PnCmdServer *conn)
{
pn_log ("begin");
- g_object_unref (G_OBJECT (conn));
+ g_object_unref (conn);
pn_log ("end");
}

diff --git a/io/pn_dc_conn.c b/io/pn_dc_conn.c
index 4dda674..ffef080 100644
--- a/io/pn_dc_conn.c
+++ b/io/pn_dc_conn.c
@@ -59,7 +59,7 @@ pn_dc_conn_new(gchar *name,
void
pn_dc_conn_free(PnDcConn *conn)
{
- g_object_unref(G_OBJECT(conn));
+ g_object_unref(conn);
}

/* PnNode stuff. */
diff --git a/io/pn_http_server.c b/io/pn_http_server.c
index a7c89b3..3d63dea 100644
--- a/io/pn_http_server.c
+++ b/io/pn_http_server.c
@@ -100,7 +100,7 @@ process_queue (PnHttpServer *http_conn,
queue_data->body_len,
NULL,
error);
- g_object_unref (G_OBJECT (queue_data->conn));
+ g_object_unref (queue_data->conn);
g_free (queue_data->body);
g_free (queue_data);
}
@@ -217,7 +217,7 @@ void
pn_http_server_free (PnHttpServer *http_conn)
{
pn_log ("begin");
- g_object_unref (G_OBJECT (http_conn));
+ g_object_unref (http_conn);
pn_log ("end");
}

@@ -524,7 +524,7 @@ close_impl (PnNode *conn)
HttpQueueData *queue_data;
while ((queue_data = g_queue_pop_head (http_conn->write_queue)))
{
- g_object_unref (G_OBJECT (queue_data->conn));
+ g_object_unref (queue_data->conn);
g_free (queue_data->body);
g_free (queue_data);
}
@@ -745,7 +745,7 @@ read_impl (PnNode *conn,
pn_node_close (child);
g_hash_table_remove (http_conn->childs, session_id);

- g_object_unref (G_OBJECT (http_conn->cur));
+ g_object_unref (http_conn->cur);
g_free (http_conn->gateway);
g_free (http_conn->last_session_id);
if ((foo = PN_NODE (g_hash_table_peek_first (http_conn->childs))))
diff --git a/io/pn_node.c b/io/pn_node.c
index a71798f..b6a27bd 100644
--- a/io/pn_node.c
+++ b/io/pn_node.c
@@ -197,7 +197,7 @@ pn_node_free (PnNode *conn)
{
g_return_if_fail (conn != NULL);
pn_log ("begin");
- g_object_unref (G_OBJECT (conn));
+ g_object_unref (conn);
pn_log ("end");
}

diff --git a/io/pn_ssl_conn.c b/io/pn_ssl_conn.c
index 6237780..70ec94a 100644
--- a/io/pn_ssl_conn.c
+++ b/io/pn_ssl_conn.c
@@ -134,7 +134,7 @@ pn_ssl_conn_free (PnSslConn *conn)
g_return_if_fail (conn);

pn_log ("begin");
- g_object_unref (G_OBJECT (conn));
+ g_object_unref (conn);
pn_log ("end");
}

--
1.6.6.1

Felipe Contreras

unread,
Feb 7, 2010, 6:30:49 PM2/7/10
to msn-...@googlegroups.com, Felipe Contreras
Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---
io/pn_cmd_server.c | 4 ++--
io/pn_dc_conn.c | 4 ++--
io/pn_http_server.c | 4 ++--
io/pn_node.c | 6 +++---
io/pn_ssl_conn.c | 2 +-
5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/io/pn_cmd_server.c b/io/pn_cmd_server.c
index acd11b0..4e7b562 100644
--- a/io/pn_cmd_server.c
+++ b/io/pn_cmd_server.c
@@ -41,7 +41,7 @@ struct PnCmdServerClass
PnNodeClass parent_class;
};

-static PnNodeClass *parent_class = NULL;
+static PnNodeClass *parent_class;

PnCmdServer *
pn_cmd_server_new (PnNodeType type)
@@ -178,7 +178,7 @@ close_impl (PnNode *conn)
if (cmd_conn->cmdproc)
msn_cmdproc_flush (cmd_conn->cmdproc);

- PN_NODE_CLASS (parent_class)->close (conn);
+ parent_class->close (conn);



pn_log ("end");
}
diff --git a/io/pn_dc_conn.c b/io/pn_dc_conn.c

index ffef080..8fa844b 100644
--- a/io/pn_dc_conn.c
+++ b/io/pn_dc_conn.c
@@ -38,7 +38,7 @@ struct PnDcConnClass {
PnNodeClass parent_class;
};

-static GObjectClass *parent_class = NULL;
+static GObjectClass *parent_class;

PnDcConn *
pn_dc_conn_new(gchar *name,
@@ -205,7 +205,7 @@ finalize(GObject *obj)
{
PnDcConn *dc_conn = PN_DC_CONN(obj);
g_free(dc_conn->rx_buf);
- G_OBJECT_CLASS(parent_class)->finalize(obj);
+ parent_class->finalize(obj);
}

static void
diff --git a/io/pn_http_server.c b/io/pn_http_server.c
index 3d63dea..9328fdb 100644
--- a/io/pn_http_server.c
+++ b/io/pn_http_server.c
@@ -67,7 +67,7 @@ struct PnHttpServerClass
PnNodeClass parent_class;
};

-static PnNodeClass *parent_class = NULL;
+static PnNodeClass *parent_class;

typedef struct
{
@@ -535,7 +535,7 @@ close_impl (PnNode *conn)
g_hash_table_remove_all (http_conn->childs);
#endif

- PN_NODE_CLASS (parent_class)->close (conn);
+ parent_class->close (conn);

pn_log ("end");
}
diff --git a/io/pn_node.c b/io/pn_node.c
index b6a27bd..5efbc8e 100644
--- a/io/pn_node.c
+++ b/io/pn_node.c
@@ -29,7 +29,7 @@

void pn_node_error (PnNode *conn);

-static GObjectClass *parent_class = NULL;
+static GObjectClass *parent_class;

GQuark
pn_node_error_quark (void)
@@ -646,7 +646,7 @@ dispose (GObject *obj)
g_free (conn->name);
}

- G_OBJECT_CLASS (parent_class)->dispose (obj);
+ parent_class->dispose (obj);

pn_log ("end");
}
@@ -654,7 +654,7 @@ dispose (GObject *obj)
static void
finalize (GObject *obj)
{
- G_OBJECT_CLASS (parent_class)->finalize (obj);
+ parent_class->finalize (obj);
}

static void
diff --git a/io/pn_ssl_conn.c b/io/pn_ssl_conn.c
index 70ec94a..06550aa 100644
--- a/io/pn_ssl_conn.c
+++ b/io/pn_ssl_conn.c
@@ -42,7 +42,7 @@ struct PnSslConnClass
PnNodeClass parent_class;
};

-static GObjectClass *parent_class = NULL;
+static GObjectClass *parent_class;

static void
read_cb (gpointer data,
--
1.6.6.1

Felipe Contreras

unread,
Feb 7, 2010, 6:30:50 PM2/7/10
to msn-...@googlegroups.com, Felipe Contreras
We might want to catch these.

Signed-off-by: Felipe Contreras <felipe.c...@gmail.com>
---

cvr/pn_peer_link.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cvr/pn_peer_link.c b/cvr/pn_peer_link.c
index 039d3ce..e363ea9 100644
--- a/cvr/pn_peer_link.c
+++ b/cvr/pn_peer_link.c
@@ -574,8 +574,8 @@ process_peer_msg(struct pn_peer_link *link,
pn_peer_call_unref(call);
break;
default:
- pn_debug("slp_process_msg: unprocessed SLP message with flags 0x%08lx",
- peer_msg->flags);
+ pn_info("slp_process_msg: unprocessed SLP message with flags 0x%08lx",
+ peer_msg->flags);
}
}

--
1.6.6.1

Reply all
Reply to author
Forward
0 new messages