Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/jangernert/FeedReader.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan Long <self@brendanlong.com>2018-04-28 21:00:53 +0300
committerBrendan Long <self@brendanlong.com>2018-04-28 21:05:04 +0300
commit9432e0e2292274d5c13363c1d07a7bc10527a288 (patch)
tree38294e2ef4f7a790bf1ab77c68108b52f582cdd8
parent2d0714aecb499080d6860a887730ca3029a186e4 (diff)
Add a lock around libvilistextum
I was running into null pointer exceptions because the globals change if it's used in multiple threads.
-rw-r--r--libraries/libVilistextum/vilistextum.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libraries/libVilistextum/vilistextum.c b/libraries/libVilistextum/vilistextum.c
index 898d9893..ba2d5259 100644
--- a/libraries/libVilistextum/vilistextum.c
+++ b/libraries/libVilistextum/vilistextum.c
@@ -13,6 +13,8 @@
#include <stdio.h>
#include <stdlib.h>
+#include <pthread.h>
+
#include "vilistextum.h"
#include "html.h"
#include "fileio.h"
@@ -20,6 +22,9 @@
/* ------------------------------------------------ */
+// libvilistextum uses globals and isn't thread-safe
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
void set_options()
{
convert_characters = 1;
@@ -40,6 +45,7 @@ char* vilistextum(char* text, int extractText)
if(text == NULL)
return NULL;
+ pthread_mutex_lock(&mutex);
error = 0;
set_options();
@@ -51,5 +57,6 @@ char* vilistextum(char* text, int extractText)
}
char* output = getOutput(strlen(text));
+ pthread_mutex_unlock(&mutex);
return output;
}