From fbdb06351385eb210c50ba6a1fc2b8c14575513e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 May 2006 19:26:54 +0000 Subject: replace memory allocation function calls with pa_xXXXX() git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@916 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/pacat.c | 46 +++++++++++++++++++++------------------------- src/utils/pactl.c | 35 ++++++++++++++++------------------- src/utils/paplay.c | 36 +++++++++++++++++------------------- 3 files changed, 54 insertions(+), 63 deletions(-) diff --git a/src/utils/pacat.c b/src/utils/pacat.c index 529cebae..51b3a48e 100644 --- a/src/utils/pacat.c +++ b/src/utils/pacat.c @@ -34,8 +34,6 @@ #include #include -#include -#include #include #define TIME_EVENT_USEC 50000 @@ -97,7 +95,7 @@ static void do_stream_write(size_t length) { buffer_index += l; if (!buffer_length) { - free(buffer); + pa_xfree(buffer); buffer = NULL; buffer_index = buffer_length = 0; } @@ -141,8 +139,7 @@ static void stream_read_callback(pa_stream *s, size_t length, void *userdata) { return; } - buffer = malloc(buffer_length = length); - assert(buffer); + buffer = pa_xmalloc(buffer_length = length); memcpy(buffer, data, length); buffer_index = 0; pa_stream_drop(s); @@ -273,8 +270,8 @@ static void stdin_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_even if (!stream || pa_stream_get_state(stream) != PA_STREAM_READY || !(l = w = pa_stream_writable_size(stream))) l = 4096; - buffer = malloc(l); - assert(buffer); + buffer = pa_xmalloc(l); + if ((r = read(fd, buffer, l)) <= 0) { if (r == 0) { pa_operation *o; @@ -331,7 +328,7 @@ static void stdout_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_eve buffer_index += r; if (!buffer_length) { - free(buffer); + pa_xfree(buffer); buffer = NULL; buffer_length = buffer_index = 0; } @@ -342,7 +339,6 @@ static void exit_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, if (verbose) fprintf(stderr, "Got signal, exiting.\n"); quit(0); - } /* Show the current latency */ @@ -479,23 +475,23 @@ int main(int argc, char *argv[]) { break; case 'd': - free(device); - device = strdup(optarg); + pa_xfree(device); + device = pa_xstrdup(optarg); break; case 's': - free(server); - server = strdup(optarg); + pa_xfree(server); + server = pa_xstrdup(optarg); break; case 'n': - free(client_name); - client_name = strdup(optarg); + pa_xfree(client_name); + client_name = pa_xstrdup(optarg); break; case ARG_STREAM_NAME: - free(stream_name); - stream_name = strdup(optarg); + pa_xfree(stream_name); + stream_name = pa_xstrdup(optarg); break; case 'v': @@ -567,7 +563,7 @@ int main(int argc, char *argv[]) { close(fd); if (!stream_name) - stream_name = strdup(argv[optind]); + stream_name = pa_xstrdup(argv[optind]); } else { fprintf(stderr, "Too many arguments.\n"); @@ -576,10 +572,10 @@ int main(int argc, char *argv[]) { } if (!client_name) - client_name = strdup(bn); + client_name = pa_xstrdup(bn); if (!stream_name) - stream_name = strdup(client_name); + stream_name = pa_xstrdup(client_name); /* Set up a new main loop */ if (!(m = pa_mainloop_new())) { @@ -659,12 +655,12 @@ quit: pa_mainloop_free(m); } - free(buffer); + pa_xfree(buffer); - free(server); - free(device); - free(client_name); - free(stream_name); + pa_xfree(server); + pa_xfree(device); + pa_xfree(client_name); + pa_xfree(stream_name); return ret; } diff --git a/src/utils/pactl.c b/src/utils/pactl.c index 7a3d3737..cc59e459 100644 --- a/src/utils/pactl.c +++ b/src/utils/pactl.c @@ -36,8 +36,6 @@ #include #include -#include -#include #if PA_API_VERSION != 9 #error Invalid Polypaudio API version @@ -511,19 +509,18 @@ static void stream_write_callback(pa_stream *s, size_t length, void *userdata) { float *d; assert(s && length && sndfile); - d = malloc(length); - assert(d); + d = pa_xmalloc(length); assert(sample_length >= length); l = length/pa_frame_size(&sample_spec); if ((sf_readf_float(sndfile, d, l)) != l) { - free(d); + pa_xfree(d); fprintf(stderr, "Premature end of file\n"); quit(1); } - pa_stream_write(s, d, length, free, 0, PA_SEEK_RELATIVE); + pa_stream_write(s, d, length, pa_xfree, 0, PA_SEEK_RELATIVE); sample_length -= length; @@ -652,13 +649,13 @@ int main(int argc, char *argv[]) { goto quit; case 's': - free(server); - server = strdup(optarg); + pa_xfree(server); + server = pa_xstrdup(optarg); break; case 'n': - free(client_name); - client_name = strdup(optarg); + pa_xfree(client_name); + client_name = pa_xstrdup(optarg); break; default: @@ -667,7 +664,7 @@ int main(int argc, char *argv[]) { } if (!client_name) - client_name = strdup(bn); + client_name = pa_xstrdup(bn); if (optind < argc) { if (!strcmp(argv[optind], "stat")) @@ -686,7 +683,7 @@ int main(int argc, char *argv[]) { } if (optind+2 < argc) - sample_name = strdup(argv[optind+2]); + sample_name = pa_xstrdup(argv[optind+2]); else { char *f = strrchr(argv[optind+1], '/'); size_t n; @@ -698,7 +695,7 @@ int main(int argc, char *argv[]) { n = strcspn(f, "."); strncpy(tmp, f, n); tmp[n] = 0; - sample_name = strdup(tmp); + sample_name = pa_xstrdup(tmp); } memset(&sfinfo, 0, sizeof(sfinfo)); @@ -719,10 +716,10 @@ int main(int argc, char *argv[]) { goto quit; } - sample_name = strdup(argv[optind+1]); + sample_name = pa_xstrdup(argv[optind+1]); if (optind+2 < argc) - device = strdup(argv[optind+2]); + device = pa_xstrdup(argv[optind+2]); } else if (!strcmp(argv[optind], "remove-sample")) { action = REMOVE_SAMPLE; @@ -731,7 +728,7 @@ int main(int argc, char *argv[]) { goto quit; } - sample_name = strdup(argv[optind+1]); + sample_name = pa_xstrdup(argv[optind+1]); } } @@ -782,9 +779,9 @@ quit: if (sndfile) sf_close(sndfile); - free(server); - free(device); - free(sample_name); + pa_xfree(server); + pa_xfree(device); + pa_xfree(sample_name); return ret; } diff --git a/src/utils/paplay.c b/src/utils/paplay.c index 5f203615..b66c13da 100644 --- a/src/utils/paplay.c +++ b/src/utils/paplay.c @@ -35,8 +35,6 @@ #include #include -#include -#include #if PA_API_VERSION != 9 #error Invalid Polypaudio API version @@ -105,7 +103,7 @@ static void stream_write_callback(pa_stream *s, size_t length, void *userdata) { if (!sndfile) return; - data = malloc(length); + data = pa_xmalloc(length); if (readf_function) { size_t k = pa_frame_size(&sample_spec); @@ -117,9 +115,9 @@ static void stream_write_callback(pa_stream *s, size_t length, void *userdata) { bytes = sf_read_raw(sndfile, data, length); if (bytes > 0) - pa_stream_write(s, data, bytes, free, 0, PA_SEEK_RELATIVE); + pa_stream_write(s, data, bytes, pa_xfree, 0, PA_SEEK_RELATIVE); else - free(data); + pa_xfree(data); if (bytes < length) { sf_close(sndfile); @@ -257,23 +255,23 @@ int main(int argc, char *argv[]) { goto quit; case 'd': - free(device); - device = strdup(optarg); + pa_xfree(device); + device = pa_xstrdup(optarg); break; case 's': - free(server); - server = strdup(optarg); + pa_xfree(server); + server = pa_xstrdup(optarg); break; case 'n': - free(client_name); - client_name = strdup(optarg); + pa_xfree(client_name); + client_name = pa_xstrdup(optarg); break; case ARG_STREAM_NAME: - free(stream_name); - stream_name = strdup(optarg); + pa_xfree(stream_name); + stream_name = pa_xstrdup(optarg); break; case 'v': @@ -351,11 +349,11 @@ int main(int argc, char *argv[]) { } if (!client_name) - client_name = strdup(bn); + client_name = pa_xstrdup(bn); if (!stream_name) { const char *n = sf_get_string(sndfile, SF_STR_TITLE); - stream_name = strdup(n ? n : filename); + stream_name = pa_xstrdup(n ? n : filename); } if (verbose) { @@ -408,10 +406,10 @@ quit: pa_mainloop_free(m); } - free(server); - free(device); - free(client_name); - free(stream_name); + pa_xfree(server); + pa_xfree(device); + pa_xfree(client_name); + pa_xfree(stream_name); if (sndfile) sf_close(sndfile); -- cgit