Permalink
Browse files

Fix up a lot of memory leaks

Based on an original patch from Pedro Kiefer <pedro@kiefer.com.br>

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information...
1 parent caebbcd commit 5590848ce82f554a96bbd0d51ce5200810e0043a @gregkh committed Aug 12, 2010
Showing with 148 additions and 0 deletions.
  1. +2 −0 lsusb.c
  2. +145 −0 names.c
  3. +1 −0 names.h
View
@@ -3694,5 +3694,7 @@ int main(int argc, char *argv[])
status = dump_one_device(devdump);
else
status = list_devices(bus, devnum, vendor, product);
+
+ names_exit();
return status;
}
View
145 names.c
@@ -467,6 +467,139 @@ static int new_countrycode(const char *name, unsigned int countrycode)
/* ---------------------------------------------------------------------- */
+static void free_vendor(void)
+{
+ struct vendor *cur, *tmp;
+ int i;
+
+ for (i = 0; i < HASHSZ; i++) {
+ cur = vendors[i];
+ while (cur) {
+ tmp = cur;
+ cur = cur->next;
+ free(tmp);
+ }
+ }
+}
+
+static void free_product(void)
+{
+ struct product *cur, *tmp;
+ int i;
+
+ for (i = 0; i < HASHSZ; i++) {
+ cur = products[i];
+ while (cur) {
+ tmp = cur;
+ cur = cur->next;
+ free(tmp);
+ }
+ }
+}
+
+static void free_class(void)
+{
+ struct class *cur, *tmp;
+ int i;
+
+ for (i = 0; i < HASHSZ; i++) {
+ cur = classes[i];
+ while (cur) {
+ tmp = cur;
+ cur = cur->next;
+ free(tmp);
+ }
+ }
+}
+
+static void free_subclass(void)
+{
+ struct subclass *cur, *tmp;
+ int i;
+
+ for (i = 0; i < HASHSZ; i++) {
+ cur = subclasses[i];
+ while (cur) {
+ tmp = cur;
+ cur = cur->next;
+ free(tmp);
+ }
+ }
+}
+
+static void free_protocol(void)
+{
+ struct protocol *cur, *tmp;
+ int i;
+
+ for (i = 0; i < HASHSZ; i++) {
+ cur = protocols[i];
+ while (cur) {
+ tmp = cur;
+ cur = cur->next;
+ free(tmp);
+ }
+ }
+}
+
+static void free_audioterminal(void)
+{
+ struct audioterminal *cur, *tmp;
+ int i;
+
+ for (i = 0; i < HASHSZ; i++) {
+ cur = audioterminals[i];
+ while (cur) {
+ tmp = cur;
+ cur = cur->next;
+ free(tmp);
+ }
+ }
+ return;
+}
+
+static void free_videoterminal(void)
+{
+ struct videoterminal *cur, *tmp;
+ int i;
+
+ for (i = 0; i < HASHSZ; i++) {
+ cur = videoterminals[i];
+ while (cur) {
+ tmp = cur;
+ cur = cur->next;
+ free(tmp);
+ }
+ }
+}
+
+static void _free_genericstrtable(struct genericstrtable *t[HASHSZ])
+{
+ struct genericstrtable *cur, *tmp;
+ int i;
+
+ for (i = 0; i < HASHSZ; i++) {
+ cur = t[i];
+ while (cur) {
+ tmp = cur;
+ cur = cur->next;
+ free(tmp);
+ }
+ }
+}
+
+static void free_genericstrtable(void)
+{
+ _free_genericstrtable(hiddescriptors);
+ _free_genericstrtable(reports);
+ _free_genericstrtable(huts);
+ _free_genericstrtable(biass);
+ _free_genericstrtable(physdess);
+ _free_genericstrtable(hutus);
+ _free_genericstrtable(langids);
+ _free_genericstrtable(countrycodes);
+}
+
#define DBG(x)
static void parse(usb_file f)
@@ -816,3 +949,15 @@ int names_init(char *n)
usb_close(f);
return 0;
}
+
+void names_exit(void)
+{
+ free_vendor();
+ free_product();
+ free_class();
+ free_subclass();
+ free_protocol();
+ free_audioterminal();
+ free_videoterminal();
+ free_genericstrtable();
+}
View
@@ -48,6 +48,7 @@ extern const char *names_physdes(u_int8_t ph);
extern const char *names_bias(u_int8_t b);
extern const char *names_countrycode(unsigned int countrycode);
extern int names_init(char *n);
+extern void names_exit(void);
/* ---------------------------------------------------------------------- */
#endif /* _NAMES_H */

0 comments on commit 5590848

Please sign in to comment.