shithub: zuke

Download patch

ref: 3aea7228518a7808c70e083f5ca0d509edf41aa8
parent: 97b5812b636750164c1c4a250a3488a90c47dc0f
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Oct 12 08:48:47 EDT 2020

icy: fix a memory leak

--- a/icy.c
+++ b/icy.c
@@ -1,7 +1,7 @@
 int
 icyfill(Meta *m)
 {
-	char *s, *e, *p, *path, *d;
+	char *s, *s0, *e, *p, *path, *d;
 	int f, n;
 
 	path = strdup(m->path);
@@ -17,10 +17,10 @@
 	if((f = dial(d, nil, nil, nil)) < 0)
 		return -1;
 	fprint(f, "GET /%s HTTP/0.9\r\nIcy-MetaData: 1\r\n\r\n", e ? e : "");
-	s = malloc(4096);
-	n = readn(f, s, 4095);
-	s[n] = 0;
-	for(; s = strchr(s, '\n');){
+	s0 = malloc(4096);
+	n = readn(f, s0, 4095);
+	s0[n] = 0;
+	for(s = s0; s = strchr(s, '\n');){
 		s++;
 		if(strncmp(s, "icy-name:", 9) == 0 && (e = strchr(s, '\r')) != nil){
 			*e = 0;
@@ -33,6 +33,7 @@
 			s = e+1;
 		}
 	}
+	free(s0);
 	close(f);
 
 	return 0;