1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#! /bin/sh /usr/share/dpatch/dpatch-run
## 13_mem_thread_fix by <hubert@uhoreg.ca>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Some memory and threading fixes and cleanups.
## DP: taken from alsaplayer CVS (committed on 2004-02-15)
@DPATCH@
--- alsaplayer-0.99.76/app/AlsaNode.cpp 16 Jan 2004 17:31:50 -0000 1.63
+++ alsaplayer-cvs/app/AlsaNode.cpp 15 Feb 2004 18:42:13 -0000 1.64
@@ -103,11 +103,11 @@
plugin->close();
if (driver_name) {
- delete driver_name;
+ delete []driver_name;
driver_name = NULL;
}
if (driver_args) {
- delete driver_args;
+ delete []driver_args;
driver_args = NULL;
}
}
@@ -226,10 +226,11 @@
}
}
+#define MAX_WRITE (128*1024)
void AlsaNode::looper(void *pointer)
{
- char *buffer_data;
+ char *buffer_data = NULL;
AlsaNode *node = (AlsaNode *)pointer;
int read_size = node->GetFragmentSize();
bool status;
@@ -238,11 +239,12 @@
assert(node->plugin);
- buffer_data = (char *)malloc(1024*128);
+ buffer_data = new char[MAX_WRITE+1];
if (!buffer_data) {
alsaplayer_error("Error allocating mix buffer");
return;
- }
+ }
+ memset(buffer_data, 0, MAX_WRITE+1);
#ifdef DEBUG
alsaplayer_error("THREAD-%d=soundcard thread\n", getpid());
#endif
@@ -267,11 +269,15 @@
node->looping = true;
read_size = node->GetFragmentSize();
+ if (read_size > MAX_WRITE) {
+ alsaplayer_error("Fragment size too large. Exitting looper");
+ pthread_exit(NULL);
+ }
while (node->looping) {
subscriber *i;
int c;
- memset(buffer_data, 0, read_size);
+ memset(buffer_data, 0, read_size * sizeof(short));
for (c = 0; c < MAX_SUB; c++) {
i = &node->subs[c];
@@ -291,8 +297,8 @@
read_size = node->GetFragmentSize(); // Change on the fly
}
- free(buffer_data);
- pthread_mutex_unlock(&node->thread_mutex);
+ delete []buffer_data;
+ //alsaplayer_error("Exitting looper thread...");
pthread_exit(NULL);
}
@@ -458,11 +464,16 @@
if (plugin->start_callbacks)
return;
- if (pthread_mutex_trylock(&thread_mutex) != 0) {
+ pthread_mutex_lock(&thread_mutex);
+ if (thread_running) {
+ //alsaplayer_error("Already looping...");
+ pthread_mutex_unlock(&thread_mutex);
return;
- }
+ }
+ //alsaplayer_error("Creating looper thread");
pthread_create(&looper_thread, NULL, (void * (*)(void *))looper, this);
thread_running = true;
+ pthread_mutex_unlock(&thread_mutex);
}
@@ -475,12 +486,14 @@
}
looping = false;
+ pthread_mutex_lock(&thread_mutex);
if (thread_running) {
if (pthread_join(looper_thread, NULL)) {
// Hmmm
}
thread_running = false;
- }
+ }
+ pthread_mutex_unlock(&thread_mutex);
}
--- alsaplayer-0.99.76/app/reader.cpp 9 Mar 2003 02:48:34 -0000 1.11
+++ alsaplayer-cvs/app/reader.cpp 15 Feb 2004 18:42:46 -0000 1.12
@@ -197,6 +197,9 @@
int i = plugin_count;
reader_plugin *plugin = plugins;
+ if (!uri) {
+ return 0;
+ }
// Search for best reader plugin
for (;i--;plugin++) {
if (plugin->can_handle (uri) > 0)
@@ -382,7 +385,10 @@
int reader_readline (reader_type *h, char *buf, int size)
{
int len = 0;
-
+
+ if (!h || !buf) {
+ return 0;
+ }
while (size && !reader_eof(h)) {
reader_read (buf, 1, h);
--- alsaplayer-0.99.76/app/Playlist.cpp 2 Nov 2003 18:30:46 -0000 1.89
+++ alsaplayer-cvs/app/Playlist.cpp 15 Feb 2004 18:43:45 -0000 1.90
@@ -444,6 +444,7 @@
delete player2;
Lock();
+ Unlock();
pthread_mutex_destroy(&playlist_mutex);
}
@@ -807,6 +808,7 @@
// Read the file
char path[READBUFSIZE + 1];
+ memset(path, 0,READBUFSIZE);
std::vector<std::string> newfiles;
// Give up if too many failures (so we don"t wait for almost ever if
|