From: Kristen Carlson Accardi <kristen@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 2/3] fix memory leaks after ppp_transmit
Date: Wed, 24 Mar 2010 10:13:24 -0700 [thread overview]
Message-ID: <1269450805-3661-3-git-send-email-kristen@linux.intel.com> (raw)
In-Reply-To: <1269450805-3661-1-git-send-email-kristen@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 4129 bytes --]
Free packets in ppp_cp after calling ppp_transmit()
---
gatchat/ppp_cp.c | 36 +++++++++++++++++++++++++++---------
1 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/gatchat/ppp_cp.c b/gatchat/ppp_cp.c
index 0f04fa1..b02f4ba 100644
--- a/gatchat/ppp_cp.c
+++ b/gatchat/ppp_cp.c
@@ -48,7 +48,7 @@ static const char *pppcp_state_strings[] =
#endif
#define pppcp_to_ppp_packet(p) \
- (p-PPP_HEADROOM)
+ (((guint8 *) p) - PPP_HEADROOM)
struct pppcp_event {
enum pppcp_event_type type;
@@ -62,6 +62,11 @@ struct pppcp_event {
#define MAX_FAILURE 5
#define CP_HEADER_SZ 4
+static void pppcp_packet_free(struct pppcp_packet *packet)
+{
+ g_free(pppcp_to_ppp_packet(packet));
+}
+
static struct pppcp_packet *pppcp_packet_new(struct pppcp_data *data,
guint type, guint bufferlen)
{
@@ -291,9 +296,11 @@ static void pppcp_send_configure_request(struct pppcp_data *data)
new_identity(data, data->config_identifier);
packet->identifier = data->config_identifier;
- ppp_transmit(data->ppp, pppcp_to_ppp_packet((guint8 *) packet),
+ ppp_transmit(data->ppp, pppcp_to_ppp_packet(packet),
ntohs(packet->length));
+ pppcp_packet_free(packet);
+
/* XXX don't retransmit right now */
#if 0
data->restart_counter--;
@@ -327,8 +334,9 @@ static void pppcp_send_configure_ack(struct pppcp_data *data,
/* match identifier of the request */
packet->identifier = pppcp_header->identifier;
- ppp_transmit(data->ppp, pppcp_to_ppp_packet((guint8 *) packet),
+ ppp_transmit(data->ppp, pppcp_to_ppp_packet(packet),
ntohs(packet->length));
+ pppcp_packet_free(packet);
}
/*
@@ -357,9 +365,10 @@ static void pppcp_send_configure_nak(struct pppcp_data *data,
&odata);
packet->identifier = pppcp_header->identifier;
- ppp_transmit(data->ppp, pppcp_to_ppp_packet((guint8 *) packet),
+ ppp_transmit(data->ppp, pppcp_to_ppp_packet(packet),
ntohs(packet->length));
+ pppcp_packet_free(packet);
}
/* if we have any unacceptable options, send a config-nak */
if (g_list_length(data->unacceptable_options)) {
@@ -377,8 +386,10 @@ static void pppcp_send_configure_nak(struct pppcp_data *data,
&odata);
packet->identifier = pppcp_header->identifier;
- ppp_transmit(data->ppp, pppcp_to_ppp_packet((guint8 *) packet),
+ ppp_transmit(data->ppp, pppcp_to_ppp_packet(packet),
ntohs(packet->length));
+
+ pppcp_packet_free(packet);
}
}
@@ -405,8 +416,10 @@ static void pppcp_send_terminate_request(struct pppcp_data *data)
data->terminate_identifier =
new_identity(data, data->terminate_identifier);
packet->identifier = data->terminate_identifier;
- ppp_transmit(data->ppp, pppcp_to_ppp_packet((guint8 *) packet),
+ ppp_transmit(data->ppp, pppcp_to_ppp_packet(packet),
ntohs(packet->length));
+
+ pppcp_packet_free(packet);
data->restart_counter--;
pppcp_start_timer(data);
}
@@ -425,8 +438,10 @@ static void pppcp_send_terminate_ack(struct pppcp_data *data,
/* match identifier of the request */
packet->identifier = pppcp_header->identifier;
- ppp_transmit(data->ppp, pppcp_to_ppp_packet((guint8 *) packet),
+ ppp_transmit(data->ppp, pppcp_to_ppp_packet(packet),
ntohs(pppcp_header->length));
+
+ pppcp_packet_free(packet);
}
/*
@@ -454,8 +469,10 @@ static void pppcp_send_code_reject(struct pppcp_data *data,
memcpy(packet->data, rejected_packet,
ntohs(packet->length - CP_HEADER_SZ));
- ppp_transmit(data->ppp, pppcp_to_ppp_packet((guint8 *) packet),
+ ppp_transmit(data->ppp, pppcp_to_ppp_packet(packet),
ntohs(packet->length));
+
+ pppcp_packet_free(packet);
}
/*
@@ -478,9 +495,10 @@ static void pppcp_send_echo_reply(struct pppcp_data *data,
packet->identifier = header->identifier;
/* magic number? */
- ppp_transmit(data->ppp, pppcp_to_ppp_packet((guint8 *) packet),
+ ppp_transmit(data->ppp, pppcp_to_ppp_packet(packet),
ntohs(packet->length));
+ pppcp_packet_free(packet);
}
static void pppcp_transition_state(enum pppcp_state new_state,
--
1.6.6.1
next prev parent reply other threads:[~2010-03-24 17:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-24 17:13 [PATCH 0/3] fix memory leaks in PPP Kristen Carlson Accardi
2010-03-24 17:13 ` [PATCH 1/3] fix memory leaks in option handling Kristen Carlson Accardi
2010-03-24 17:13 ` Kristen Carlson Accardi [this message]
2010-03-24 17:13 ` [PATCH 3/3] fix memory leak in ppp_auth Kristen Carlson Accardi
2010-03-24 20:22 ` [PATCH 0/3] fix memory leaks in PPP Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269450805-3661-3-git-send-email-kristen@linux.intel.com \
--to=kristen@linux.intel.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox