From: =?utf-8?b?0L3QsNCx?= <nabijaczleweli@nabijaczleweli.xyz>
Date: Sun, 23 Feb 2025 03:24:17 +0100
Subject: Don't return dangling pointer from snd()

---
 src/festival.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/festival.c b/src/festival.c
index f33b22e..78781c0 100644
--- a/src/festival.c
+++ b/src/festival.c
@@ -73,23 +73,20 @@ static void on_prepend_who_checkbutton_clicked(GtkWidget *widget, void *data);
 static void on_replace_url_checkbutton_clicked(GtkWidget *widget, void *data);
 static void on_announce_events_checkbutton_clicked(GtkWidget *widget, void *data);
 
-static char * snd(char * sndType);
 G_GNUC_CONST static gint badchar(char c);
 static char *unlinkify_text(const char *text);
 
 /*---------Functions---------------------*/
 
 /** This function needs to be better written **/
-static char * snd(char * sndType) {
+static void snd(const char * sndType, char * daemon) {
 
-  char *daemon = "";
   if (strcmp (sndType, "arts") == 0 ||
       strcmp (sndType, "esd")  == 0 ||
       strcmp (sndType, "alsa") == 0 ||
       strcmp (sndType, "automatic") == 0) {
 
     FILE *which_pf;
-    char sndserver[1024];
     if (strcmp (sndType, "arts") == 0)
       which_pf= popen("command -v artsdsp","r");
     else if (strcmp (sndType, "esd") == 0)
@@ -98,14 +95,13 @@ static char * snd(char * sndType) {
       which_pf= popen("command -v aoss","r");
     else if (strcmp (sndType, "automatic") == 0)
       which_pf= popen("command -v artsdsp","r");
-    fscanf(which_pf,"%1023s",sndserver);
+    fscanf(which_pf,"%1023s",daemon);
     pclose(which_pf);
-    daemon=sndserver;
   }
   else{
     purple_debug(PURPLE_DEBUG_INFO, "pidgin festival sound method ","%s", sndType);
+    daemon[0] = '\0';
   }
-  return daemon;
 }
 
 G_GNUC_CONST static gint badchar(char c)
@@ -531,7 +527,9 @@ plugin_load(PurplePlugin *plugin) {
     return FALSE;
 
   char proc[1024];
-  snprintf(proc,1024, "%s %s", snd((char *)purple_prefs_get_string("/pidgin/sound/method")), line);
+  snd((char *)purple_prefs_get_string("/pidgin/sound/method"), proc);
+  strcat(proc, " ");
+  strcat(proc, line);
   purple_debug(PURPLE_DEBUG_INFO, "pidgin festival","%s", proc);
 
   festival_pf= popen(proc,"w");
