raop: Handle the reponse header memory allocation more sensibly.

In theory the callback called after reading headers could free our whole object, so we should not
take it upon ourselves to free the headers after the call to the callback.
This commit is contained in:
Colin Guthrie 2009-03-01 23:17:07 +00:00
parent b75a4b437a
commit 8a00c00943

View file

@ -101,26 +101,27 @@ pa_rtsp_client* pa_rtsp_client_new(pa_mainloop_api *mainloop, const char* hostna
void pa_rtsp_client_free(pa_rtsp_client* c) {
if (c) {
if (c->sc)
pa_socket_client_unref(c->sc);
if (c->ioline)
pa_ioline_close(c->ioline);
else if (c->io)
pa_iochannel_free(c->io);
pa_assert(c);
if (c->sc)
pa_socket_client_unref(c->sc);
if (c->ioline)
pa_ioline_close(c->ioline);
else if (c->io)
pa_iochannel_free(c->io);
pa_xfree(c->hostname);
pa_xfree(c->url);
pa_xfree(c->localip);
pa_xfree(c->session);
pa_xfree(c->transport);
pa_xfree(c->last_header);
if (c->header_buffer)
pa_strbuf_free(c->header_buffer);
if (c->response_headers)
pa_headerlist_free(c->response_headers);
pa_headerlist_free(c->headers);
pa_xfree(c->hostname);
pa_xfree(c->url);
pa_xfree(c->localip);
pa_xfree(c->session);
pa_xfree(c->transport);
pa_xfree(c->last_header);
if (c->header_buffer)
pa_strbuf_free(c->header_buffer);
if (c->response_headers)
pa_headerlist_free(c->response_headers);
pa_headerlist_free(c->headers);
}
pa_xfree(c);
}
@ -141,8 +142,6 @@ static void headers_read(pa_rtsp_client *c) {
c->transport = pa_xstrdup(pa_headerlist_gets(c->response_headers, "Transport"));
if (!c->session || !c->transport) {
pa_headerlist_free(c->response_headers);
c->response_headers = NULL;
pa_log("Invalid SETUP response.");
return;
}
@ -160,8 +159,6 @@ static void headers_read(pa_rtsp_client *c) {
}
if (0 == c->rtp_port) {
/* Error no server_port in response */
pa_headerlist_free(c->response_headers);
c->response_headers = NULL;
pa_log("Invalid SETUP response (no port number).");
return;
}
@ -169,9 +166,6 @@ static void headers_read(pa_rtsp_client *c) {
/* Call our callback */
c->callback(c, c->state, c->response_headers, c->userdata);
pa_headerlist_free(c->response_headers);
c->response_headers = NULL;
}
@ -201,7 +195,8 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
}
if (c->waiting && 0 == strcmp("RTSP/1.0 200 OK", s2)) {
c->waiting = 0;
pa_assert(!c->response_headers);
if (c->response_headers)
pa_headerlist_free(c->response_headers);
c->response_headers = pa_headerlist_new();
goto exit;
}
@ -353,9 +348,12 @@ void pa_rtsp_set_callback(pa_rtsp_client *c, pa_rtsp_cb_t callback, void *userda
void pa_rtsp_disconnect(pa_rtsp_client *c) {
pa_assert(c);
if (c->io)
if (c->ioline)
pa_ioline_close(c->ioline);
else if (c->io)
pa_iochannel_free(c->io);
c->io = NULL;
c->ioline = NULL;
}