More movements of spandsp to the sue of custom allocation routines

This commit is contained in:
Steve Underwood 2013-08-06 01:10:48 +08:00
parent d5e4089c22
commit 799402dd5b
21 changed files with 109 additions and 86 deletions

View File

@ -42,6 +42,7 @@
#include <assert.h> #include <assert.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/complex.h" #include "spandsp/complex.h"
#include "spandsp/dds.h" #include "spandsp/dds.h"
#include "spandsp/power_meter.h" #include "spandsp/power_meter.h"
@ -166,7 +167,7 @@ SPAN_DECLARE(fsk_tx_state_t *) fsk_tx_init(fsk_tx_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (fsk_tx_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (fsk_tx_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -186,7 +187,7 @@ SPAN_DECLARE(int) fsk_tx_release(fsk_tx_state_t *s)
SPAN_DECLARE(int) fsk_tx_free(fsk_tx_state_t *s) SPAN_DECLARE(int) fsk_tx_free(fsk_tx_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
@ -328,7 +329,7 @@ SPAN_DECLARE(fsk_rx_state_t *) fsk_rx_init(fsk_rx_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (fsk_rx_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (fsk_rx_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -348,7 +349,7 @@ SPAN_DECLARE(int) fsk_rx_release(fsk_rx_state_t *s)
SPAN_DECLARE(int) fsk_rx_free(fsk_rx_state_t *s) SPAN_DECLARE(int) fsk_rx_free(fsk_rx_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -35,6 +35,7 @@
#include <stdio.h> #include <stdio.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/async.h" #include "spandsp/async.h"
#include "spandsp/crc.h" #include "spandsp/crc.h"
#include "spandsp/bit_operations.h" #include "spandsp/bit_operations.h"
@ -314,7 +315,7 @@ SPAN_DECLARE(hdlc_rx_state_t *) hdlc_rx_init(hdlc_rx_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (hdlc_rx_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (hdlc_rx_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -350,7 +351,7 @@ SPAN_DECLARE(int) hdlc_rx_release(hdlc_rx_state_t *s)
SPAN_DECLARE(int) hdlc_rx_free(hdlc_rx_state_t *s) SPAN_DECLARE(int) hdlc_rx_free(hdlc_rx_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
@ -592,7 +593,7 @@ SPAN_DECLARE(hdlc_tx_state_t *) hdlc_tx_init(hdlc_tx_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (hdlc_tx_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (hdlc_tx_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -624,7 +625,7 @@ SPAN_DECLARE(int) hdlc_tx_release(hdlc_tx_state_t *s)
SPAN_DECLARE(int) hdlc_tx_free(hdlc_tx_state_t *s) SPAN_DECLARE(int) hdlc_tx_free(hdlc_tx_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -42,6 +42,7 @@
#include "floating_fudge.h" #include "floating_fudge.h"
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
#include "spandsp/saturated.h" #include "spandsp/saturated.h"
#include "spandsp/ima_adpcm.h" #include "spandsp/ima_adpcm.h"
@ -282,7 +283,7 @@ SPAN_DECLARE(ima_adpcm_state_t *) ima_adpcm_init(ima_adpcm_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (ima_adpcm_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (ima_adpcm_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
/*endif*/ /*endif*/
@ -301,7 +302,7 @@ SPAN_DECLARE(int) ima_adpcm_release(ima_adpcm_state_t *s)
SPAN_DECLARE(int) ima_adpcm_free(ima_adpcm_state_t *s) SPAN_DECLARE(int) ima_adpcm_free(ima_adpcm_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -52,6 +52,7 @@
#include <assert.h> #include <assert.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/saturated.h" #include "spandsp/saturated.h"
@ -712,7 +713,7 @@ SPAN_DECLARE(int) image_translate_restart(image_translate_state_t *s, int input_
{ {
if (s->raw_pixel_row[i] == NULL) if (s->raw_pixel_row[i] == NULL)
{ {
if ((s->raw_pixel_row[i] = (uint8_t *) malloc(raw_row_size)) == NULL) if ((s->raw_pixel_row[i] = (uint8_t *) span_alloc(raw_row_size)) == NULL)
return -1; return -1;
} }
memset(s->raw_pixel_row[i], 0, raw_row_size); memset(s->raw_pixel_row[i], 0, raw_row_size);
@ -729,7 +730,7 @@ SPAN_DECLARE(int) image_translate_restart(image_translate_state_t *s, int input_
{ {
if (s->pixel_row[i] == NULL) if (s->pixel_row[i] == NULL)
{ {
if ((s->pixel_row[i] = (uint8_t *) malloc(raw_row_size)) == NULL) if ((s->pixel_row[i] = (uint8_t *) span_alloc(raw_row_size)) == NULL)
return -1; return -1;
} }
memset(s->pixel_row[i], 0, raw_row_size); memset(s->pixel_row[i], 0, raw_row_size);
@ -757,7 +758,7 @@ SPAN_DECLARE(image_translate_state_t *) image_translate_init(image_translate_sta
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (image_translate_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (image_translate_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -794,12 +795,12 @@ SPAN_DECLARE(int) image_translate_release(image_translate_state_t *s)
{ {
if (s->raw_pixel_row[i]) if (s->raw_pixel_row[i])
{ {
free(s->raw_pixel_row[i]); span_free(s->raw_pixel_row[i]);
s->raw_pixel_row[i] = NULL; s->raw_pixel_row[i] = NULL;
} }
if (s->pixel_row[i]) if (s->pixel_row[i])
{ {
free(s->pixel_row[i]); span_free(s->pixel_row[i]);
s->pixel_row[i] = NULL; s->pixel_row[i] = NULL;
} }
} }
@ -812,7 +813,7 @@ SPAN_DECLARE(int) image_translate_free(image_translate_state_t *s)
int res; int res;
res = image_translate_release(s); res = image_translate_release(s);
free(s); span_free(s);
return res; return res;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -57,9 +57,9 @@
SPAN_DECLARE(void) modem_echo_can_free(modem_echo_can_state_t *ec) SPAN_DECLARE(void) modem_echo_can_free(modem_echo_can_state_t *ec)
{ {
fir16_free(&ec->fir_state); fir16_free(&ec->fir_state);
free(ec->fir_taps32); span_free(ec->fir_taps32);
free(ec->fir_taps16); span_free(ec->fir_taps16);
free(ec); span_free(ec);
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
@ -74,7 +74,7 @@ SPAN_DECLARE(modem_echo_can_state_t *) modem_echo_can_init(int len)
ec->curr_pos = ec->taps - 1; ec->curr_pos = ec->taps - 1;
if ((ec->fir_taps32 = (int32_t *) span_alloc(ec->taps*sizeof(int32_t))) == NULL) if ((ec->fir_taps32 = (int32_t *) span_alloc(ec->taps*sizeof(int32_t))) == NULL)
{ {
free(ec); span_free(ec);
return NULL; return NULL;
} }
memset(ec->fir_taps32, 0, ec->taps*sizeof(int32_t)); memset(ec->fir_taps32, 0, ec->taps*sizeof(int32_t));

View File

@ -51,6 +51,7 @@
#include <tiffio.h> #include <tiffio.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/bit_operations.h" #include "spandsp/bit_operations.h"
#include "spandsp/bitstream.h" #include "spandsp/bitstream.h"
@ -3016,7 +3017,7 @@ SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s,
alloced = FALSE; alloced = FALSE;
if (s == NULL) if (s == NULL)
{ {
if ((s = (t31_state_t *) malloc(sizeof (*s))) == NULL) if ((s = (t31_state_t *) span_alloc(sizeof (*s))) == NULL)
return NULL; return NULL;
/*endif*/ /*endif*/
alloced = TRUE; alloced = TRUE;
@ -3071,7 +3072,7 @@ SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s,
if ((s->rx_queue = queue_init(NULL, 4096, QUEUE_WRITE_ATOMIC | QUEUE_READ_ATOMIC)) == NULL) if ((s->rx_queue = queue_init(NULL, 4096, QUEUE_WRITE_ATOMIC | QUEUE_READ_ATOMIC)) == NULL)
{ {
if (alloced) if (alloced)
free(s); span_free(s);
/*endif*/ /*endif*/
return NULL; return NULL;
} }
@ -3100,7 +3101,7 @@ SPAN_DECLARE(int) t31_release(t31_state_t *s)
SPAN_DECLARE(int) t31_free(t31_state_t *s) SPAN_DECLARE(int) t31_free(t31_state_t *s)
{ {
t31_release(s); t31_release(s);
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -47,6 +47,7 @@
#include <tiffio.h> #include <tiffio.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/bit_operations.h" #include "spandsp/bit_operations.h"
#include "spandsp/t38_core.h" #include "spandsp/t38_core.h"
@ -1109,7 +1110,7 @@ SPAN_DECLARE(t38_core_state_t *) t38_core_init(t38_core_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (t38_core_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (t38_core_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -1157,7 +1158,7 @@ SPAN_DECLARE(int) t38_core_release(t38_core_state_t *s)
SPAN_DECLARE(int) t38_core_free(t38_core_state_t *s) SPAN_DECLARE(int) t38_core_free(t38_core_state_t *s)
{ {
if (s) if (s)
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -50,6 +50,7 @@
#include <tiffio.h> #include <tiffio.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/queue.h" #include "spandsp/queue.h"
#include "spandsp/dc_restore.h" #include "spandsp/dc_restore.h"
@ -2267,7 +2268,7 @@ SPAN_DECLARE(t38_gateway_state_t *) t38_gateway_init(t38_gateway_state_t *s,
/*endif*/ /*endif*/
if (s == NULL) if (s == NULL)
{ {
if ((s = (t38_gateway_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (t38_gateway_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
/*endif*/ /*endif*/
} }
@ -2332,7 +2333,7 @@ SPAN_DECLARE(int) t38_gateway_release(t38_gateway_state_t *s)
SPAN_DECLARE(int) t38_gateway_free(t38_gateway_state_t *s) SPAN_DECLARE(int) t38_gateway_free(t38_gateway_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -46,6 +46,7 @@
#include <assert.h> #include <assert.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/queue.h" #include "spandsp/queue.h"
#include "spandsp/dc_restore.h" #include "spandsp/dc_restore.h"
@ -351,7 +352,7 @@ SPAN_DECLARE(t38_non_ecm_buffer_state_t *) t38_non_ecm_buffer_init(t38_non_ecm_b
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (t38_non_ecm_buffer_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (t38_non_ecm_buffer_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -371,7 +372,7 @@ SPAN_DECLARE(int) t38_non_ecm_buffer_release(t38_non_ecm_buffer_state_t *s)
SPAN_DECLARE(int) t38_non_ecm_buffer_free(t38_non_ecm_buffer_state_t *s) SPAN_DECLARE(int) t38_non_ecm_buffer_free(t38_non_ecm_buffer_state_t *s)
{ {
if (s) if (s)
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -46,6 +46,7 @@
#include <tiffio.h> #include <tiffio.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/bit_operations.h" #include "spandsp/bit_operations.h"
#include "spandsp/queue.h" #include "spandsp/queue.h"
@ -1525,7 +1526,7 @@ SPAN_DECLARE(t38_terminal_state_t *) t38_terminal_init(t38_terminal_state_t *s,
if (s == NULL) if (s == NULL)
{ {
if ((s = (t38_terminal_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (t38_terminal_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
/*endif*/ /*endif*/
} }
@ -1564,7 +1565,7 @@ SPAN_DECLARE(int) t38_terminal_release(t38_terminal_state_t *s)
SPAN_DECLARE(int) t38_terminal_free(t38_terminal_state_t *s) SPAN_DECLARE(int) t38_terminal_free(t38_terminal_state_t *s)
{ {
t38_terminal_release(s); t38_terminal_release(s);
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -50,6 +50,7 @@
#include <assert.h> #include <assert.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/saturated.h" #include "spandsp/saturated.h"
@ -742,7 +743,7 @@ static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s)
span_log(&s->logging, SPAN_LOG_FLOW, "Unspecified libjpeg error.\n"); span_log(&s->logging, SPAN_LOG_FLOW, "Unspecified libjpeg error.\n");
if (s->scan_line_out) if (s->scan_line_out)
{ {
free(s->scan_line_out); span_free(s->scan_line_out);
s->scan_line_out = NULL; s->scan_line_out = NULL;
} }
if (s->out) if (s->out)
@ -802,12 +803,12 @@ static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s)
set_itu_fax(s); set_itu_fax(s);
if ((s->scan_line_in = (JSAMPROW) malloc(s->samples_per_pixel*s->image_width)) == NULL) if ((s->scan_line_in = (JSAMPROW) span_alloc(s->samples_per_pixel*s->image_width)) == NULL)
return -1; return -1;
if (s->image_type == T4_IMAGE_TYPE_COLOUR_8BIT) if (s->image_type == T4_IMAGE_TYPE_COLOUR_8BIT)
{ {
if ((s->scan_line_out = (JSAMPROW) malloc(s->samples_per_pixel*s->image_width)) == NULL) if ((s->scan_line_out = (JSAMPROW) span_alloc(s->samples_per_pixel*s->image_width)) == NULL)
return -1; return -1;
for (i = 0; i < s->compressor.image_height; i++) for (i = 0; i < s->compressor.image_height; i++)
@ -828,7 +829,7 @@ static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s)
if (s->scan_line_out) if (s->scan_line_out)
{ {
free(s->scan_line_out); span_free(s->scan_line_out);
s->scan_line_out = NULL; s->scan_line_out = NULL;
} }
jpeg_finish_compress(&s->compressor); jpeg_finish_compress(&s->compressor);
@ -841,13 +842,13 @@ static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s)
#else #else
s->buf_size = s->buf_size =
s->compressed_image_size = ftell(s->out); s->compressed_image_size = ftell(s->out);
if ((s->compressed_buf = malloc(s->compressed_image_size)) == NULL) if ((s->compressed_buf = span_alloc(s->compressed_image_size)) == NULL)
return -1; return -1;
if (fseek(s->out, 0, SEEK_SET) != 0) if (fseek(s->out, 0, SEEK_SET) != 0)
{ {
fclose(s->out); fclose(s->out);
s->out = NULL; s->out = NULL;
free(s->compressed_buf); span_free(s->compressed_buf);
s->compressed_buf = NULL; s->compressed_buf = NULL;
return -1; return -1;
} }
@ -855,7 +856,7 @@ static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s)
{ {
fclose(s->out); fclose(s->out);
s->out = NULL; s->out = NULL;
free(s->compressed_buf); span_free(s->compressed_buf);
s->compressed_buf = NULL; s->compressed_buf = NULL;
return -1; return -1;
} }
@ -986,7 +987,7 @@ SPAN_DECLARE(t42_encode_state_t *) t42_encode_init(t42_encode_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (t42_encode_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (t42_encode_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -1016,7 +1017,7 @@ SPAN_DECLARE(int) t42_encode_free(t42_encode_state_t *s)
int ret; int ret;
ret = t42_encode_release(s); ret = t42_encode_release(s);
free(s); span_free(s);
return ret; return ret;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
@ -1087,7 +1088,7 @@ static int t42_itulab_jpeg_to_srgb(t42_decode_state_t *s)
span_log(&s->logging, SPAN_LOG_FLOW, "Unspecified libjpeg error.\n"); span_log(&s->logging, SPAN_LOG_FLOW, "Unspecified libjpeg error.\n");
if (s->scan_line_out) if (s->scan_line_out)
{ {
free(s->scan_line_out); span_free(s->scan_line_out);
s->scan_line_out = NULL; s->scan_line_out = NULL;
} }
if (s->in) if (s->in)
@ -1155,12 +1156,12 @@ static int t42_itulab_jpeg_to_srgb(t42_decode_state_t *s)
jpeg_start_decompress(&s->decompressor); jpeg_start_decompress(&s->decompressor);
if ((s->scan_line_in = malloc(s->samples_per_pixel*s->image_width)) == NULL) if ((s->scan_line_in = span_alloc(s->samples_per_pixel*s->image_width)) == NULL)
return -1; return -1;
if (s->samples_per_pixel == 3) if (s->samples_per_pixel == 3)
{ {
if ((s->scan_line_out = malloc(s->samples_per_pixel*s->image_width)) == NULL) if ((s->scan_line_out = span_alloc(s->samples_per_pixel*s->image_width)) == NULL)
return -1; return -1;
while (s->decompressor.output_scanline < s->image_length) while (s->decompressor.output_scanline < s->image_length)
@ -1181,12 +1182,12 @@ static int t42_itulab_jpeg_to_srgb(t42_decode_state_t *s)
if (s->scan_line_in) if (s->scan_line_in)
{ {
free(s->scan_line_in); span_free(s->scan_line_in);
s->scan_line_in = NULL; s->scan_line_in = NULL;
} }
if (s->scan_line_out) if (s->scan_line_out)
{ {
free(s->scan_line_out); span_free(s->scan_line_out);
s->scan_line_out = NULL; s->scan_line_out = NULL;
} }
jpeg_finish_decompress(&s->decompressor); jpeg_finish_decompress(&s->decompressor);
@ -1243,7 +1244,7 @@ SPAN_DECLARE(int) t42_decode_put(t42_decode_state_t *s, const uint8_t data[], si
if (s->compressed_image_size + len > s->buf_size) if (s->compressed_image_size + len > s->buf_size)
{ {
if ((buf = (uint8_t *) realloc(s->compressed_buf, s->compressed_image_size + len + 10000)) == NULL) if ((buf = (uint8_t *) span_realloc(s->compressed_buf, s->compressed_image_size + len + 10000)) == NULL)
return -1; return -1;
s->buf_size = s->compressed_image_size + len + 10000; s->buf_size = s->compressed_image_size + len + 10000;
s->compressed_buf = buf; s->compressed_buf = buf;
@ -1340,7 +1341,7 @@ SPAN_DECLARE(t42_decode_state_t *) t42_decode_init(t42_decode_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (t42_decode_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (t42_decode_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -1363,12 +1364,12 @@ SPAN_DECLARE(int) t42_decode_release(t42_decode_state_t *s)
{ {
if (s->scan_line_in) if (s->scan_line_in)
{ {
free(s->scan_line_in); span_free(s->scan_line_in);
s->scan_line_in = NULL; s->scan_line_in = NULL;
} }
if (s->scan_line_out) if (s->scan_line_out)
{ {
free(s->scan_line_out); span_free(s->scan_line_out);
s->scan_line_out = NULL; s->scan_line_out = NULL;
} }
jpeg_destroy_decompress(&s->decompressor); jpeg_destroy_decompress(&s->decompressor);
@ -1379,7 +1380,7 @@ SPAN_DECLARE(int) t42_decode_release(t42_decode_state_t *s)
} }
if (s->comment) if (s->comment)
{ {
free(s->comment); span_free(s->comment);
s->comment = NULL; s->comment = NULL;
} }
return 0; return 0;
@ -1391,7 +1392,7 @@ SPAN_DECLARE(int) t42_decode_free(t42_decode_state_t *s)
int ret; int ret;
ret = t42_decode_release(s); ret = t42_decode_release(s);
free(s); span_free(s);
return ret; return ret;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -44,6 +44,7 @@
#include <setjmp.h> #include <setjmp.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/async.h" #include "spandsp/async.h"
#include "spandsp/timezone.h" #include "spandsp/timezone.h"
@ -133,7 +134,9 @@ static int t43_create_header(t43_encode_state_t *s, uint8_t data[], size_t len)
{ {
int pos; int pos;
int val[6]; int val[6];
#if 0
int bytes_per_entry; int bytes_per_entry;
#endif
pos = 0; pos = 0;
unpack_16(data, 0xFFA8); unpack_16(data, 0xFFA8);
@ -345,7 +348,7 @@ SPAN_DECLARE(t43_encode_state_t *) t43_encode_init(t43_encode_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (t43_encode_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (t43_encode_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -380,7 +383,7 @@ SPAN_DECLARE(int) t43_encode_free(t43_encode_state_t *s)
t85_encode_free(&s->t85); t85_encode_free(&s->t85);
ret = t43_encode_release(s); ret = t43_encode_release(s);
free(s); span_free(s);
return ret; return ret;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
@ -700,7 +703,7 @@ static int t85_row_write_handler(void *user_data, const uint8_t buf[], size_t le
if (s->buf == NULL) if (s->buf == NULL)
{ {
image_size = s->samples_per_pixel*s->t85.xd*s->t85.yd; image_size = s->samples_per_pixel*s->t85.xd*s->t85.yd;
if ((s->buf = malloc(image_size)) == NULL) if ((s->buf = span_alloc(image_size)) == NULL)
return -1; return -1;
memset(s->buf, 0, image_size); memset(s->buf, 0, image_size);
} }
@ -761,6 +764,7 @@ SPAN_DECLARE(int) t43_decode_put(t43_decode_state_t *s, const uint8_t data[], si
} }
/* Now deal the bit-planes, one after another. */ /* Now deal the bit-planes, one after another. */
total_len = 0;
while (s->current_bit_plane < s->t85.bit_planes) while (s->current_bit_plane < s->t85.bit_planes)
{ {
j = s->current_bit_plane; j = s->current_bit_plane;
@ -882,7 +886,7 @@ SPAN_DECLARE(t43_decode_state_t *) t43_decode_init(t43_decode_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (t43_decode_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (t43_decode_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -922,7 +926,7 @@ SPAN_DECLARE(int) t43_decode_free(t43_decode_state_t *s)
ret = t43_decode_release(s); ret = t43_decode_release(s);
t85_decode_free(&s->t85); t85_decode_free(&s->t85);
free(s); span_free(s);
return ret; return ret;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -79,6 +79,7 @@
#include <tiffio.h> #include <tiffio.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/bit_operations.h" #include "spandsp/bit_operations.h"
#include "spandsp/async.h" #include "spandsp/async.h"
@ -138,17 +139,17 @@ static int free_buffers(t4_t6_decode_state_t *s)
{ {
if (s->cur_runs) if (s->cur_runs)
{ {
free(s->cur_runs); span_free(s->cur_runs);
s->cur_runs = NULL; s->cur_runs = NULL;
} }
if (s->ref_runs) if (s->ref_runs)
{ {
free(s->ref_runs); span_free(s->ref_runs);
s->ref_runs = NULL; s->ref_runs = NULL;
} }
if (s->row_buf) if (s->row_buf)
{ {
free(s->row_buf); span_free(s->row_buf);
s->row_buf = NULL; s->row_buf = NULL;
} }
s->bytes_per_row = 0; s->bytes_per_row = 0;
@ -824,10 +825,10 @@ SPAN_DECLARE(int) t4_t6_decode_restart(t4_t6_decode_state_t *s, int image_width)
if (s->bytes_per_row == 0 || image_width != s->image_width) if (s->bytes_per_row == 0 || image_width != s->image_width)
{ {
/* Allocate the space required for decoding the new row length. */ /* Allocate the space required for decoding the new row length. */
if ((bufptr = (uint32_t *) realloc(s->cur_runs, run_space)) == NULL) if ((bufptr = (uint32_t *) span_realloc(s->cur_runs, run_space)) == NULL)
return -1; return -1;
s->cur_runs = bufptr; s->cur_runs = bufptr;
if ((bufptr = (uint32_t *) realloc(s->ref_runs, run_space)) == NULL) if ((bufptr = (uint32_t *) span_realloc(s->ref_runs, run_space)) == NULL)
return -1; return -1;
s->ref_runs = bufptr; s->ref_runs = bufptr;
s->image_width = image_width; s->image_width = image_width;
@ -835,7 +836,7 @@ SPAN_DECLARE(int) t4_t6_decode_restart(t4_t6_decode_state_t *s, int image_width)
bytes_per_row = (image_width + 7)/8; bytes_per_row = (image_width + 7)/8;
if (bytes_per_row != s->bytes_per_row) if (bytes_per_row != s->bytes_per_row)
{ {
if ((bufptr8 = (uint8_t *) realloc(s->row_buf, bytes_per_row)) == NULL) if ((bufptr8 = (uint8_t *) span_realloc(s->row_buf, bytes_per_row)) == NULL)
return -1; return -1;
s->row_buf = bufptr8; s->row_buf = bufptr8;
s->bytes_per_row = bytes_per_row; s->bytes_per_row = bytes_per_row;
@ -892,7 +893,7 @@ SPAN_DECLARE(t4_t6_decode_state_t *) t4_t6_decode_init(t4_t6_decode_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (t4_t6_decode_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (t4_t6_decode_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -919,7 +920,7 @@ SPAN_DECLARE(int) t4_t6_decode_free(t4_t6_decode_state_t *s)
int ret; int ret;
ret = t4_t6_decode_release(s); ret = t4_t6_decode_release(s);
free(s); span_free(s);
return ret; return ret;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -76,6 +76,7 @@
#include <tiffio.h> #include <tiffio.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/bit_operations.h" #include "spandsp/bit_operations.h"
#include "spandsp/async.h" #include "spandsp/async.h"
@ -373,17 +374,17 @@ static int free_buffers(t4_t6_encode_state_t *s)
{ {
if (s->cur_runs) if (s->cur_runs)
{ {
free(s->cur_runs); span_free(s->cur_runs);
s->cur_runs = NULL; s->cur_runs = NULL;
} }
if (s->ref_runs) if (s->ref_runs)
{ {
free(s->ref_runs); span_free(s->ref_runs);
s->ref_runs = NULL; s->ref_runs = NULL;
} }
if (s->bitstream) if (s->bitstream)
{ {
free(s->bitstream); span_free(s->bitstream);
s->bitstream = NULL; s->bitstream = NULL;
} }
s->bytes_per_row = 0; s->bytes_per_row = 0;
@ -1026,13 +1027,13 @@ SPAN_DECLARE(int) t4_t6_encode_set_image_width(t4_t6_encode_state_t *s, int imag
s->bytes_per_row = (s->image_width + 7)/8; s->bytes_per_row = (s->image_width + 7)/8;
run_space = (s->image_width + 4)*sizeof(uint32_t); run_space = (s->image_width + 4)*sizeof(uint32_t);
if ((bufptr = (uint32_t *) realloc(s->cur_runs, run_space)) == NULL) if ((bufptr = (uint32_t *) span_realloc(s->cur_runs, run_space)) == NULL)
return -1; return -1;
s->cur_runs = bufptr; s->cur_runs = bufptr;
if ((bufptr = (uint32_t *) realloc(s->ref_runs, run_space)) == NULL) if ((bufptr = (uint32_t *) span_realloc(s->ref_runs, run_space)) == NULL)
return -1; return -1;
s->ref_runs = bufptr; s->ref_runs = bufptr;
if ((bufptr8 = (uint8_t *) realloc(s->bitstream, (s->image_width + 1)*sizeof(uint16_t))) == NULL) if ((bufptr8 = (uint8_t *) span_realloc(s->bitstream, (s->image_width + 1)*sizeof(uint16_t))) == NULL)
return -1; return -1;
s->bitstream = bufptr8; s->bitstream = bufptr8;
} }
@ -1151,7 +1152,7 @@ SPAN_DECLARE(t4_t6_encode_state_t *) t4_t6_encode_init(t4_t6_encode_state_t *s,
{ {
if (s == NULL) if (s == NULL)
{ {
if ((s = (t4_t6_encode_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (t4_t6_encode_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -1181,7 +1182,7 @@ SPAN_DECLARE(int) t4_t6_encode_free(t4_t6_encode_state_t *s)
int ret; int ret;
ret = t4_t6_encode_release(s); ret = t4_t6_encode_release(s);
free(s); span_free(s);
return ret; return ret;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -42,6 +42,7 @@
#include "floating_fudge.h" #include "floating_fudge.h"
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/complex.h" #include "spandsp/complex.h"
@ -449,7 +450,7 @@ SPAN_DECLARE(v17_tx_state_t *) v17_tx_init(v17_tx_state_t *s, int bit_rate, int
} }
if (s == NULL) if (s == NULL)
{ {
if ((s = (v17_tx_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (v17_tx_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -473,7 +474,7 @@ SPAN_DECLARE(int) v17_tx_release(v17_tx_state_t *s)
SPAN_DECLARE(int) v17_tx_free(v17_tx_state_t *s) SPAN_DECLARE(int) v17_tx_free(v17_tx_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -43,6 +43,7 @@
#include "floating_fudge.h" #include "floating_fudge.h"
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/queue.h" #include "spandsp/queue.h"
#include "spandsp/async.h" #include "spandsp/async.h"
@ -1113,7 +1114,7 @@ SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s,
if (s == NULL) if (s == NULL)
{ {
if ((s = (v18_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (v18_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -1204,7 +1205,7 @@ SPAN_DECLARE(int) v18_release(v18_state_t *s)
SPAN_DECLARE(int) v18_free(v18_state_t *s) SPAN_DECLARE(int) v18_free(v18_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -45,6 +45,7 @@
#include "floating_fudge.h" #include "floating_fudge.h"
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/complex.h" #include "spandsp/complex.h"
@ -700,7 +701,7 @@ SPAN_DECLARE(v22bis_state_t *) v22bis_init(v22bis_state_t *s,
} }
if (s == NULL) if (s == NULL)
{ {
if ((s = (v22bis_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (v22bis_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -748,7 +749,7 @@ SPAN_DECLARE(int) v22bis_release(v22bis_state_t *s)
SPAN_DECLARE(int) v22bis_free(v22bis_state_t *s) SPAN_DECLARE(int) v22bis_free(v22bis_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -43,6 +43,7 @@
#include "floating_fudge.h" #include "floating_fudge.h"
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
#include "spandsp/math_fixed.h" #include "spandsp/math_fixed.h"
@ -1087,7 +1088,7 @@ SPAN_DECLARE(v27ter_rx_state_t *) v27ter_rx_init(v27ter_rx_state_t *s, int bit_r
} }
if (s == NULL) if (s == NULL)
{ {
if ((s = (v27ter_rx_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (v27ter_rx_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -1110,7 +1111,7 @@ SPAN_DECLARE(int) v27ter_rx_release(v27ter_rx_state_t *s)
SPAN_DECLARE(int) v27ter_rx_free(v27ter_rx_state_t *s) SPAN_DECLARE(int) v27ter_rx_free(v27ter_rx_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -42,6 +42,7 @@
#include "floating_fudge.h" #include "floating_fudge.h"
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/complex.h" #include "spandsp/complex.h"
@ -404,7 +405,7 @@ SPAN_DECLARE(v27ter_tx_state_t *) v27ter_tx_init(v27ter_tx_state_t *s, int bit_r
} }
if (s == NULL) if (s == NULL)
{ {
if ((s = (v27ter_tx_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (v27ter_tx_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -427,7 +428,7 @@ SPAN_DECLARE(int) v27ter_tx_release(v27ter_tx_state_t *s)
SPAN_DECLARE(int) v27ter_tx_free(v27ter_tx_state_t *s) SPAN_DECLARE(int) v27ter_tx_free(v27ter_tx_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -43,6 +43,7 @@
#include "floating_fudge.h" #include "floating_fudge.h"
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
#include "spandsp/math_fixed.h" #include "spandsp/math_fixed.h"
@ -1148,7 +1149,7 @@ SPAN_DECLARE(v29_rx_state_t *) v29_rx_init(v29_rx_state_t *s, int bit_rate, put_
} }
if (s == NULL) if (s == NULL)
{ {
if ((s = (v29_rx_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (v29_rx_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -1176,7 +1177,7 @@ SPAN_DECLARE(int) v29_rx_release(v29_rx_state_t *s)
SPAN_DECLARE(int) v29_rx_free(v29_rx_state_t *s) SPAN_DECLARE(int) v29_rx_free(v29_rx_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -42,6 +42,7 @@
#include "floating_fudge.h" #include "floating_fudge.h"
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
#include "spandsp/logging.h" #include "spandsp/logging.h"
#include "spandsp/complex.h" #include "spandsp/complex.h"
@ -388,7 +389,7 @@ SPAN_DECLARE(v29_tx_state_t *) v29_tx_init(v29_tx_state_t *s, int bit_rate, int
} }
if (s == NULL) if (s == NULL)
{ {
if ((s = (v29_tx_state_t *) malloc(sizeof(*s))) == NULL) if ((s = (v29_tx_state_t *) span_alloc(sizeof(*s))) == NULL)
return NULL; return NULL;
} }
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
@ -411,7 +412,7 @@ SPAN_DECLARE(int) v29_tx_release(v29_tx_state_t *s)
SPAN_DECLARE(int) v29_tx_free(v29_tx_state_t *s) SPAN_DECLARE(int) v29_tx_free(v29_tx_state_t *s)
{ {
free(s); span_free(s);
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/