[polypaudio-commits] r916 - in /trunk/src/utils: pacat.c pactl.c paplay.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed May 17 12:26:54 PDT 2006


Author: lennart
Date: Wed May 17 21:26:54 2006
New Revision: 916

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=916&root=polypaudio&view=rev
Log:
replace memory allocation function calls with pa_xXXXX() 

Modified:
    trunk/src/utils/pacat.c
    trunk/src/utils/pactl.c
    trunk/src/utils/paplay.c

Modified: trunk/src/utils/pacat.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/utils/pacat.c?rev=916&root=polypaudio&r1=915&r2=916&view=diff
==============================================================================
--- trunk/src/utils/pacat.c (original)
+++ trunk/src/utils/pacat.c Wed May 17 21:26:54 2006
@@ -34,8 +34,6 @@
 #include <fcntl.h>
 
 #include <polyp/polypaudio.h>
-#include <polyp/mainloop.h>
-#include <polyp/mainloop-signal.h>
 #include <polypcore/util.h>
 
 #define TIME_EVENT_USEC 50000
@@ -97,7 +95,7 @@
     buffer_index += l;
     
     if (!buffer_length) {
-        free(buffer);
+        pa_xfree(buffer);
         buffer = NULL;
         buffer_index = buffer_length = 0;
     }
@@ -141,8 +139,7 @@
         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 @@
     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 @@
     buffer_index += r;
 
     if (!buffer_length) {
-        free(buffer);
+        pa_xfree(buffer);
         buffer = NULL;
         buffer_length = buffer_index = 0;
     }
@@ -342,7 +339,6 @@
     if (verbose)
         fprintf(stderr, "Got signal, exiting.\n");
     quit(0);
-    
 }
 
 /* Show the current latency */
@@ -479,23 +475,23 @@
                 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 @@
             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 @@
     }
 
     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 @@
         pa_mainloop_free(m);
     }
 
-    free(buffer);
-
-    free(server);
-    free(device);
-    free(client_name);
-    free(stream_name);
+    pa_xfree(buffer);
+
+    pa_xfree(server);
+    pa_xfree(device);
+    pa_xfree(client_name);
+    pa_xfree(stream_name);
     
     return ret;
 }

Modified: trunk/src/utils/pactl.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/utils/pactl.c?rev=916&root=polypaudio&r1=915&r2=916&view=diff
==============================================================================
--- trunk/src/utils/pactl.c (original)
+++ trunk/src/utils/pactl.c Wed May 17 21:26:54 2006
@@ -36,8 +36,6 @@
 #include <sndfile.h>
 
 #include <polyp/polypaudio.h>
-#include <polyp/mainloop.h>
-#include <polyp/mainloop-signal.h>
 
 #if PA_API_VERSION != 9
 #error Invalid Polypaudio API version
@@ -511,19 +509,18 @@
     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 @@
                 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 @@
     }
 
     if (!client_name)
-        client_name = strdup(bn);
+        client_name = pa_xstrdup(bn);
     
     if (optind < argc) {
         if (!strcmp(argv[optind], "stat"))
@@ -686,7 +683,7 @@
             }
 
             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 @@
                 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 @@
                 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 @@
                 goto quit;
             }
 
-            sample_name = strdup(argv[optind+1]);
+            sample_name = pa_xstrdup(argv[optind+1]);
         }
     }
 
@@ -782,9 +779,9 @@
     if (sndfile)
         sf_close(sndfile);
 
-    free(server);
-    free(device);
-    free(sample_name);
+    pa_xfree(server);
+    pa_xfree(device);
+    pa_xfree(sample_name);
 
     return ret;
 }

Modified: trunk/src/utils/paplay.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/utils/paplay.c?rev=916&root=polypaudio&r1=915&r2=916&view=diff
==============================================================================
--- trunk/src/utils/paplay.c (original)
+++ trunk/src/utils/paplay.c Wed May 17 21:26:54 2006
@@ -35,8 +35,6 @@
 #include <sndfile.h>
 
 #include <polyp/polypaudio.h>
-#include <polyp/mainloop.h>
-#include <polyp/mainloop-signal.h>
 
 #if PA_API_VERSION != 9
 #error Invalid Polypaudio API version
@@ -105,7 +103,7 @@
     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 @@
         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 @@
                 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 @@
     }
 
     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 @@
         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);




More information about the pulseaudio-commits mailing list