OOps :) Viva i potenziali segmentation fault! :D

Leonardo Robol [2011-05-07 17:14]
OOps :) Viva i potenziali segmentation fault! :D
Filename
audio_switcher.c
diff --git a/audio_switcher.c b/audio_switcher.c
index ff00888..2f83fd4 100644
--- a/audio_switcher.c
+++ b/audio_switcher.c
@@ -25,7 +25,7 @@ success_callback(pa_context *c, int success, char* new_output)
   GError* error = NULL;
   char *title, *body;

-  body = (char*) malloc(sizeof(char) * 255);
+

   /* Set messages of the notification based on the success
    * of the switching operation */
@@ -37,6 +37,7 @@ success_callback(pa_context *c, int success, char* new_output)
   else
     {
       title = "Audio switched";
+      body = (char*) malloc(sizeof(char) * 255);
       if (strlen(new_output) < 235)
 	sprintf(body, "New active output: %s", new_output);
       else
@@ -51,7 +52,8 @@ success_callback(pa_context *c, int success, char* new_output)
 			    &error);

   /* Free vars */
-  free (body);
+  if (success)
+    free (body);

   /* Exit the pulseaudio mainloop */
   pa_mainloop_quit(mainloop, success);
ViewGit