mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-05-16 21:19:33 +00:00
leak protection, better than mighty putty
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7141 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
4ca4a18f53
commit
9f6f77014f
@ -1135,12 +1135,16 @@ SWITCH_DECLARE(void) switch_core_db_test_reactive(switch_core_db_t *db, char *te
|
|||||||
\return SWITCH_STATUS_SUCCESS if the file is opened
|
\return SWITCH_STATUS_SUCCESS if the file is opened
|
||||||
\note the loadable module used is chosen based on the file extension
|
\note the loadable module used is chosen based on the file extension
|
||||||
*/
|
*/
|
||||||
SWITCH_DECLARE(switch_status_t) switch_core_file_open(_In_ switch_file_handle_t *fh,
|
SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, const char *func, int line,
|
||||||
|
_In_ switch_file_handle_t *fh,
|
||||||
_In_z_ const char *file_path,
|
_In_z_ const char *file_path,
|
||||||
_In_ uint8_t channels,
|
_In_ uint8_t channels,
|
||||||
_In_ uint32_t rate,
|
_In_ uint32_t rate,
|
||||||
_In_ unsigned int flags,
|
_In_ unsigned int flags,
|
||||||
_In_opt_ switch_memory_pool_t *pool);
|
_In_opt_ switch_memory_pool_t *pool);
|
||||||
|
#define switch_core_file_open(_fh, _file_path, _channels, _rate, _flags, _pool) \
|
||||||
|
switch_core_perform_file_open(__FILE__, __SWITCH_FUNC__, __LINE__, _fh, _file_path, _channels, _rate, _flags, _pool)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Read media from a file handle
|
\brief Read media from a file handle
|
||||||
\param fh the file handle to read from (must be initilized by you memset all 0 for read, fill in channels and rate for write)
|
\param fh the file handle to read from (must be initilized by you memset all 0 for read, fill in channels and rate for write)
|
||||||
|
@ -301,6 +301,9 @@ struct switch_file_handle {
|
|||||||
switch_buffer_t *buffer;
|
switch_buffer_t *buffer;
|
||||||
switch_byte_t *dbuf;
|
switch_byte_t *dbuf;
|
||||||
switch_size_t dbuflen;
|
switch_size_t dbuflen;
|
||||||
|
const char *file;
|
||||||
|
const char *func;
|
||||||
|
int line;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! \brief Abstract interface to an asr module */
|
/*! \brief Abstract interface to an asr module */
|
||||||
|
@ -979,9 +979,7 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread,
|
|||||||
switch_event_fire(&event);
|
switch_event_fire(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_core_timer_destroy(&timer);
|
|
||||||
|
|
||||||
if (switch_test_flag(conference, CFLAG_DESTRUCT)) {
|
|
||||||
|
|
||||||
switch_mutex_lock(conference->mutex);
|
switch_mutex_lock(conference->mutex);
|
||||||
conference_stop_file(conference, FILE_STOP_ASYNC);
|
conference_stop_file(conference, FILE_STOP_ASYNC);
|
||||||
@ -1034,9 +1032,10 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread,
|
|||||||
switch_clear_flag_locked(imember, MFLAG_RUNNING);
|
switch_clear_flag_locked(imember, MFLAG_RUNNING);
|
||||||
}
|
}
|
||||||
switch_mutex_unlock(conference->member_mutex);
|
switch_mutex_unlock(conference->member_mutex);
|
||||||
|
|
||||||
switch_mutex_unlock(conference->mutex);
|
switch_mutex_unlock(conference->mutex);
|
||||||
|
|
||||||
|
if (switch_test_flag(conference, CFLAG_DESTRUCT)) {
|
||||||
|
switch_core_timer_destroy(&timer);
|
||||||
switch_mutex_lock(globals.hash_mutex);
|
switch_mutex_lock(globals.hash_mutex);
|
||||||
switch_core_hash_delete(globals.conference_hash, conference->name);
|
switch_core_hash_delete(globals.conference_hash, conference->name);
|
||||||
switch_mutex_unlock(globals.hash_mutex);
|
switch_mutex_unlock(globals.hash_mutex);
|
||||||
|
@ -51,6 +51,9 @@ struct local_stream_context {
|
|||||||
switch_mutex_t *audio_mutex;
|
switch_mutex_t *audio_mutex;
|
||||||
switch_buffer_t *audio_buffer;
|
switch_buffer_t *audio_buffer;
|
||||||
int err;
|
int err;
|
||||||
|
const char *file;
|
||||||
|
const char *func;
|
||||||
|
int line;
|
||||||
struct local_stream_context *next;
|
struct local_stream_context *next;
|
||||||
};
|
};
|
||||||
typedef struct local_stream_context local_stream_context_t;
|
typedef struct local_stream_context local_stream_context_t;
|
||||||
@ -195,10 +198,16 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
|
|||||||
if (used >= source->prebuf || (source->total && used > source->samples * 2)) {
|
if (used >= source->prebuf || (source->total && used > source->samples * 2)) {
|
||||||
used = switch_buffer_read(audio_buffer, dist_buf, source->samples * 2);
|
used = switch_buffer_read(audio_buffer, dist_buf, source->samples * 2);
|
||||||
if (source->total) {
|
if (source->total) {
|
||||||
|
|
||||||
switch_mutex_lock(source->mutex);
|
switch_mutex_lock(source->mutex);
|
||||||
for (cp = source->context_list; cp; cp = cp->next) {
|
for (cp = source->context_list; cp; cp = cp->next) {
|
||||||
switch_mutex_lock(cp->audio_mutex);
|
switch_mutex_lock(cp->audio_mutex);
|
||||||
|
if (switch_buffer_inuse(cp->audio_buffer) > source->samples * 128) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Leaking stream handle! [%s() %s:%d]\n", cp->func, cp->file, cp->line);
|
||||||
|
switch_buffer_zero(cp->audio_buffer);
|
||||||
|
} else {
|
||||||
switch_buffer_write(cp->audio_buffer, dist_buf, used);
|
switch_buffer_write(cp->audio_buffer, dist_buf, used);
|
||||||
|
}
|
||||||
switch_mutex_unlock(cp->audio_mutex);
|
switch_mutex_unlock(cp->audio_mutex);
|
||||||
}
|
}
|
||||||
switch_mutex_unlock(source->mutex);
|
switch_mutex_unlock(source->mutex);
|
||||||
@ -277,6 +286,9 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
context->source = source;
|
context->source = source;
|
||||||
|
context->file = handle->file;
|
||||||
|
context->func = handle->func;
|
||||||
|
context->line = handle->line;
|
||||||
|
|
||||||
switch_mutex_lock(source->mutex);
|
switch_mutex_lock(source->mutex);
|
||||||
context->next = source->context_list;
|
context->next = source->context_list;
|
||||||
|
@ -34,8 +34,13 @@
|
|||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include "private/switch_core_pvt.h"
|
#include "private/switch_core_pvt.h"
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status_t) switch_core_file_open(switch_file_handle_t *fh,
|
SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, const char *func, int line,
|
||||||
const char *file_path, uint8_t channels, uint32_t rate, unsigned int flags, switch_memory_pool_t *pool)
|
switch_file_handle_t *fh,
|
||||||
|
const char *file_path,
|
||||||
|
uint8_t channels,
|
||||||
|
uint32_t rate,
|
||||||
|
unsigned int flags,
|
||||||
|
switch_memory_pool_t *pool)
|
||||||
{
|
{
|
||||||
char *ext;
|
char *ext;
|
||||||
switch_status_t status;
|
switch_status_t status;
|
||||||
@ -64,6 +69,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_open(switch_file_handle_t *fh,
|
|||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fh->file = file;
|
||||||
|
fh->func = func;
|
||||||
|
fh->line = line;
|
||||||
|
|
||||||
fh->flags = flags;
|
fh->flags = flags;
|
||||||
if (pool) {
|
if (pool) {
|
||||||
fh->memory_pool = pool;
|
fh->memory_pool = pool;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user