diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-09-13 21:45:21 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-09-13 21:45:21 +0000 |
commit | 18a82a6fce76be0883a431380495510010515fff (patch) | |
tree | ac944dbeeff679dc836b602fe8aec0da4ec43b99 | |
parent | 12f41aa6ff9529a80a182754d0855dccb11978ac (diff) |
avoid multiple allocs/leak in *_async calls
-rw-r--r-- | src/sdp.c | 48 |
1 files changed, 33 insertions, 15 deletions
@@ -3159,14 +3159,20 @@ int sdp_service_search_async(sdp_session_t *session, const sdp_list_t *search, u return -1; t = session->priv; - t->reqbuf = malloc(SDP_REQ_BUFFER_SIZE); + + /* check if the buffer is already allocated */ + if (t->rsp_concat_buf.data) + free(t->rsp_concat_buf.data); + memset(&t->rsp_concat_buf, 0, sizeof(sdp_buf_t)); + if (!t->reqbuf) { - t->err = ENOMEM; - goto end; + t->reqbuf = malloc(SDP_REQ_BUFFER_SIZE); + if (!t->reqbuf) { + t->err = ENOMEM; + goto end; + } } - memset(t->reqbuf, 0, SDP_REQ_BUFFER_SIZE); - memset((char *)&t->rsp_concat_buf, 0, sizeof(sdp_buf_t)); reqhdr = (sdp_pdu_hdr_t *) t->reqbuf; reqhdr->tid = htons(sdp_gen_tid(session)); @@ -3257,14 +3263,20 @@ int sdp_service_attr_async(sdp_session_t *session, uint32_t handle, sdp_attrreq_ return -1; t = session->priv; - t->reqbuf = malloc(SDP_REQ_BUFFER_SIZE); + + /* check if the buffer is already allocated */ + if (t->rsp_concat_buf.data) + free(t->rsp_concat_buf.data); + memset(&t->rsp_concat_buf, 0, sizeof(sdp_buf_t)); + if (!t->reqbuf) { - t->err = ENOMEM; - goto end; + t->reqbuf = malloc(SDP_REQ_BUFFER_SIZE); + if (!t->reqbuf) { + t->err = ENOMEM; + goto end; + } } - memset(t->reqbuf, 0, SDP_REQ_BUFFER_SIZE); - memset((char *)&t->rsp_concat_buf, 0, sizeof(sdp_buf_t)); reqhdr = (sdp_pdu_hdr_t *) t->reqbuf; reqhdr->tid = htons(sdp_gen_tid(session)); @@ -3366,14 +3378,20 @@ int sdp_service_search_attr_async(sdp_session_t *session, const sdp_list_t *sear return -1; t = session->priv; - t->reqbuf = malloc(SDP_REQ_BUFFER_SIZE); + + /* check if the buffer is already allocated */ + if (t->rsp_concat_buf.data) + free(t->rsp_concat_buf.data); + memset(&t->rsp_concat_buf, 0, sizeof(sdp_buf_t)); + if (!t->reqbuf) { - t->err = ENOMEM; - goto end; + t->reqbuf = malloc(SDP_REQ_BUFFER_SIZE); + if (!t->reqbuf) { + t->err = ENOMEM; + goto end; + } } - memset(t->reqbuf, 0, SDP_REQ_BUFFER_SIZE); - memset((char *)&t->rsp_concat_buf, 0, sizeof(sdp_buf_t)); reqhdr = (sdp_pdu_hdr_t *) t->reqbuf; reqhdr->tid = htons(sdp_gen_tid(session)); |