Re: repeatable jack related segfaults

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Julien Claassen wrote [2010-09-06] :
Hello everyone!
I'm experiencing trouble with jack and multiple servers. The moment I start a second jackserver (for net I/O) and try:
jack_lsp -s new_name
  jack_lsp segfaults.

[follow-up: jack-devel]

Hi!

I have been bitten too, and found the bug:

jack_get_ports() may return NULL if no ports matched,
and jack_lsp uses this function on line 138 like this:

   ports = jack_get_ports( client, NULL, NULL, 0)

   for (i = 0; ports[i]; ++i) {
      ...
   }

which obviously does not check for NULL.

Attached is a patch that fixes this.
Note that this also touches libjack/clients.c because
I think it is wrong to return NULL when no ports match.
There should be a distinction between a failed malloc and
no matching ports.
The array is already allocated, and the user has to free it
anyway, so there is nothing wrong with returning it empty.

Patch is against SVN but should apply with offsets against
0.118, too.

Bug test case:
   console1> jackd -dnet
   console2> jack_lsp
       Segmentation Fault

Cheers,
Mathis

Index: libjack/client.c
===================================================================
--- libjack/client.c	(Revision 4066)
+++ libjack/client.c	(Arbeitskopie)
@@ -2796,11 +2796,6 @@
 
 	matching_ports[match_cnt] = 0;
 
-	if (match_cnt == 0) {
-		free (matching_ports);
-		matching_ports = 0;
-	}
-
 	return matching_ports;
 }
 
Index: tools/lsp.c
===================================================================
--- tools/lsp.c	(Revision 4066)
+++ tools/lsp.c	(Arbeitskopie)
@@ -135,7 +135,10 @@
 		return 1;
 	}
 
-	ports = jack_get_ports (client, NULL, NULL, 0);
+ 	if ((ports = jack_get_ports(client, NULL, NULL, 0)) == NULL) {
+     fprintf (stderr, "jack_get_ports() returned NULL.");
+     goto cleanup;
+   }
 
 	for (i = 0; ports[i]; ++i) {
 		// skip over any that don't match ALL of the strings presented at command line
@@ -211,6 +214,8 @@
 			}
 		}
 	}
+
+cleanup:
 	jack_client_close (client);
 	exit (0);
 }
Index: jack/jack.h
===================================================================
--- jack/jack.h	(Revision 4066)
+++ jack/jack.h	(Arbeitskopie)
@@ -869,8 +869,8 @@
  * If zero, no selection based on flags will be carried out.
  *
  * @return a NULL-terminated array of ports that match the specified
- * arguments.  The caller is responsible for calling jack_free(3) any
- * non-NULL returned value.
+ * arguments, or NULL on error. The caller is responsible for calling 
+ * jack_free(3) any non-NULL returned value.
  *
  * @see jack_port_name_size(), jack_port_type_size()
  */
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@xxxxxxxxxxxxxxxxxxxx
http://lists.linuxaudio.org/listinfo/linux-audio-user

[Index of Archives]     [Linux Sound]     [ALSA Users]     [Pulse Audio]     [ALSA Devel]     [Sox Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux