Skip to contentSkip to conversation

snd_user_file: fix memory leak

PATCH Applied Andreas Schwab 2 participants 2 messages Nov 3, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 snd_user_file: fix memory leak

Call wordfree if and only if wordfree returns zero or WRDE_NOSPACE

---
 src/userfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/userfile.c +3 -2
index 3a73836..72779da 100644
@@ -44,19 +44,20 @@ int snd_user_file(const char *file, char **result)
 	err = wordexp(file, &we, WRDE_NOCMD);
 	switch (err) {
 	case WRDE_NOSPACE:
+		wordfree(&we);
 		return -ENOMEM;
 	case 0:
 		if (we.we_wordc == 1)
 			break;
+		wordfree(&we);
 		/* fall thru */
 	default:
-		wordfree(&we);
 		return -EINVAL;
 	}
 	*result = strdup(we.we_wordv[0]);
+	wordfree(&we);
 	if (*result == NULL)
 		return -ENOMEM;
-	wordfree(&we);
 	return 0;
 }
 
Signature · 6 lines
2.1.3

-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Applied
#1 lore raw

At Mon, 03 Nov 2014 17:22:28 +0100,

Quoted 4 lines · Andreas Schwab

Call wordfree if and only if wordfree returns zero or WRDE_NOSPACE

Thanks, applied.

Takashi

Quoted 43 lines
---
 src/userfile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/userfile.c +3 -2
index 3a73836..72779da 100644
@@ -44,19 +44,20 @@ int snd_user_file(const char *file, char **result)
 	err = wordexp(file, &we, WRDE_NOCMD);
 	switch (err) {
 	case WRDE_NOSPACE:
+		wordfree(&we);
 		return -ENOMEM;
 	case 0:
 		if (we.we_wordc == 1)
 			break;
+		wordfree(&we);
 		/* fall thru */
 	default:
-		wordfree(&we);
 		return -EINVAL;
 	}
 	*result = strdup(we.we_wordv[0]);
+	wordfree(&we);
 	if (*result == NULL)
 		return -ENOMEM;
-	wordfree(&we);
 	return 0;
 }
 
Signature · 10 lines
2.1.3

-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel