summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThe Android Automerger2011-11-02 23:04:38 -0500
committerThe Android Automerger2011-11-02 23:04:38 -0500
commitb1966c5e76eb0090822ab02aec056f032b70e2ff (patch)
treebcc2169da254bec93d5c0a35b518f5d36b2d38c4
parent08ffd07a8867e13ea24989409a9e8aed9268c548 (diff)
downloadplatform-system-core-android-4.0.1_r1.1.tar.gz
platform-system-core-android-4.0.1_r1.1.tar.xz
platform-system-core-android-4.0.1_r1.1.zip
Revert "Merge "libnl_2: Fix memory leaks" into ics-mr0"android-4.0.1_r1.2android-4.0.1_r1.1android-4.0.1_r1
This reverts commit 4f7c0843bbaa9cb4ec3a7890461cebbee689530a, reversing changes made to 6fb3df8d468a105b49c1cdbbdcb061dc8de022a4.
-rw-r--r--libnl_2/handlers.c10
-rw-r--r--libnl_2/netlink.c16
-rw-r--r--libnl_2/socket.c35
3 files changed, 27 insertions, 34 deletions
diff --git a/libnl_2/handlers.c b/libnl_2/handlers.c
index 48dcab4a8..ec8d51270 100644
--- a/libnl_2/handlers.c
+++ b/libnl_2/handlers.c
@@ -39,14 +39,16 @@ fail:
39struct nl_cb *nl_cb_clone(struct nl_cb *orig) 39struct nl_cb *nl_cb_clone(struct nl_cb *orig)
40{ 40{
41 struct nl_cb *new_cb; 41 struct nl_cb *new_cb;
42 int new_refcnt;
42 43
43 new_cb = nl_cb_alloc(NL_CB_DEFAULT); 44 new_cb = nl_cb_alloc(NL_CB_DEFAULT);
44 if (new_cb == NULL) 45 if (new_cb == NULL)
45 goto fail; 46 goto fail;
46 47
47 /* Copy original and set refcount to 1 */ 48 /* Preserve reference count and copy original */
49 new_refcnt = new_cb->cb_refcnt;
48 memcpy(new_cb, orig, sizeof(*orig)); 50 memcpy(new_cb, orig, sizeof(*orig));
49 new_cb->cb_refcnt = 1; 51 new_cb->cb_refcnt = new_refcnt;
50 52
51 return new_cb; 53 return new_cb;
52fail: 54fail:
@@ -82,9 +84,9 @@ struct nl_cb *nl_cb_get(struct nl_cb *cb)
82 84
83void nl_cb_put(struct nl_cb *cb) 85void nl_cb_put(struct nl_cb *cb)
84{ 86{
85 if (!cb)
86 return;
87 cb->cb_refcnt--; 87 cb->cb_refcnt--;
88 if (cb->cb_refcnt <= 0) 88 if (cb->cb_refcnt <= 0)
89 free(cb); 89 free(cb);
90
90} 91}
92
diff --git a/libnl_2/netlink.c b/libnl_2/netlink.c
index ee3d600f7..cc2f88e68 100644
--- a/libnl_2/netlink.c
+++ b/libnl_2/netlink.c
@@ -59,14 +59,15 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla, \
59{ 59{
60 int rc = -1; 60 int rc = -1;
61 int sk_flags; 61 int sk_flags;
62 int RECV_BUF_SIZE = getpagesize(); 62 int RECV_BUF_SIZE;
63 int errsv; 63 int errsv;
64 struct iovec recvmsg_iov; 64 struct iovec recvmsg_iov;
65 struct msghdr msg; 65 struct msghdr msg;
66 66
67 /* Allocate buffer */ 67 /* Allocate buffer */
68 RECV_BUF_SIZE = getpagesize();
68 *buf = (unsigned char *) malloc(RECV_BUF_SIZE); 69 *buf = (unsigned char *) malloc(RECV_BUF_SIZE);
69 if (!(*buf)) { 70 if (!buf) {
70 rc = -ENOMEM; 71 rc = -ENOMEM;
71 goto fail; 72 goto fail;
72 } 73 }
@@ -90,11 +91,8 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla, \
90 errsv = errno; 91 errsv = errno;
91 fcntl(sk->s_fd, F_SETFL, sk_flags); 92 fcntl(sk->s_fd, F_SETFL, sk_flags);
92 93
93 if (rc < 0) { 94 if (rc < 0)
94 rc = -errsv; 95 rc = -errsv;
95 free(*buf);
96 *buf = NULL;
97 }
98 96
99fail: 97fail:
100 return rc; 98 return rc;
@@ -110,6 +108,7 @@ int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb)
110 int rc, cb_rc = NL_OK, done = 0; 108 int rc, cb_rc = NL_OK, done = 0;
111 109
112 do { 110 do {
111
113 unsigned char *buf; 112 unsigned char *buf;
114 int i, rem, flags; 113 int i, rem, flags;
115 struct nlmsghdr *nlh; 114 struct nlmsghdr *nlh;
@@ -128,7 +127,7 @@ int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb)
128 127
129 /* Check for callbacks */ 128 /* Check for callbacks */
130 129
131 msg = (struct nl_msg *) malloc(sizeof(struct nl_msg)); 130 msg = (struct nl_msg *)malloc(sizeof(struct nl_msg));
132 memset(msg, 0, sizeof(*msg)); 131 memset(msg, 0, sizeof(*msg));
133 msg->nm_nlh = nlh; 132 msg->nm_nlh = nlh;
134 133
@@ -188,6 +187,7 @@ int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb)
188 if (done) 187 if (done)
189 break; 188 break;
190 } 189 }
190
191 free(buf); 191 free(buf);
192 buf = NULL; 192 buf = NULL;
193 193
@@ -197,7 +197,7 @@ int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb)
197 197
198success: 198success:
199fail: 199fail:
200 return rc; 200 return rc;
201} 201}
202 202
203/* Send raw data over netlink socket */ 203/* Send raw data over netlink socket */
diff --git a/libnl_2/socket.c b/libnl_2/socket.c
index d906cac27..ce54f19ba 100644
--- a/libnl_2/socket.c
+++ b/libnl_2/socket.c
@@ -31,7 +31,7 @@ int nl_socket_add_membership(struct nl_sock *sk, int group)
31} 31}
32 32
33/* Allocate new netlink socket. */ 33/* Allocate new netlink socket. */
34static struct nl_sock *_nl_socket_alloc(void) 34struct nl_sock *nl_socket_alloc(void)
35{ 35{
36 struct nl_sock *sk; 36 struct nl_sock *sk;
37 struct timeval tv; 37 struct timeval tv;
@@ -39,13 +39,13 @@ static struct nl_sock *_nl_socket_alloc(void)
39 39
40 sk = (struct nl_sock *) malloc(sizeof(struct nl_sock)); 40 sk = (struct nl_sock *) malloc(sizeof(struct nl_sock));
41 if (!sk) 41 if (!sk)
42 return NULL; 42 goto fail;
43 memset(sk, 0, sizeof(*sk)); 43 memset(sk, 0, sizeof(*sk));
44 44
45 /* Get current time */ 45 /* Get current time */
46 46
47 if (gettimeofday(&tv, NULL)) 47 if (gettimeofday(&tv, NULL))
48 goto fail; 48 return NULL;
49 else 49 else
50 sk->s_seq_next = (int) tv.tv_sec; 50 sk->s_seq_next = (int) tv.tv_sec;
51 51
@@ -59,36 +59,24 @@ static struct nl_sock *_nl_socket_alloc(void)
59 sk->s_peer.nl_pid = 0; /* Kernel */ 59 sk->s_peer.nl_pid = 0; /* Kernel */
60 sk->s_peer.nl_groups = 0; /* No groups */ 60 sk->s_peer.nl_groups = 0; /* No groups */
61 61
62 return sk; 62 cb = (struct nl_cb *) malloc(sizeof(struct nl_cb));
63fail:
64 free(sk);
65 return NULL;
66}
67
68/* Allocate new netlink socket. */
69struct nl_sock *nl_socket_alloc(void)
70{
71 struct nl_sock *sk = _nl_socket_alloc();
72 struct nl_cb *cb;
73
74 if (!sk)
75 return NULL;
76
77 cb = nl_cb_alloc(NL_CB_DEFAULT);
78 if (!cb) 63 if (!cb)
79 goto cb_fail; 64 goto cb_fail;
80 sk->s_cb = cb; 65 memset(cb, 0, sizeof(*cb));
66 sk->s_cb = nl_cb_alloc(NL_CB_DEFAULT);
67
68
81 return sk; 69 return sk;
82cb_fail: 70cb_fail:
83 free(sk); 71 free(sk);
72fail:
84 return NULL; 73 return NULL;
85} 74}
86 75
87/* Allocate new socket with custom callbacks. */ 76/* Allocate new socket with custom callbacks. */
88struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb) 77struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb)
89{ 78{
90 struct nl_sock *sk = _nl_socket_alloc(); 79 struct nl_sock *sk = nl_socket_alloc();
91
92 if (!sk) 80 if (!sk)
93 return NULL; 81 return NULL;
94 82
@@ -96,6 +84,7 @@ struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb)
96 nl_cb_get(cb); 84 nl_cb_get(cb);
97 85
98 return sk; 86 return sk;
87
99} 88}
100 89
101/* Free a netlink socket. */ 90/* Free a netlink socket. */
@@ -127,3 +116,5 @@ int nl_socket_get_fd(struct nl_sock *sk)
127{ 116{
128 return sk->s_fd; 117 return sk->s_fd;
129} 118}
119
120