Skip to content

Commit

Permalink
code clean-up
Browse files Browse the repository at this point in the history
be more prudent before freeing memory
  • Loading branch information
lyonel committed Oct 12, 2021
1 parent 0b8149a commit 353866c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/usb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ static bool load_usbids(const string & name)
buffer[linelen-1] = '\0'; // chop \n
string line = string(buffer);
free(buffer);
buffer = NULL;

description = NULL;
t = 0;
Expand Down Expand Up @@ -338,6 +339,7 @@ static bool load_usbids(const string & name)
}
}
}
if(buffer != NULL) free(buffer);
}

fclose(usbids);
Expand Down Expand Up @@ -393,6 +395,7 @@ bool scan_usb(hwNode & n)
{
string line = hw::strip(string(buffer));
free(buffer);
buffer = NULL;

if(line.length()<=0)
{
Expand Down Expand Up @@ -497,6 +500,7 @@ bool scan_usb(hwNode & n)
}
}
}
if(buffer != NULL) free(buffer);
}
if(defined)
addUSBChild(n, device, bus, lev, prnt);
Expand Down

0 comments on commit 353866c

Please sign in to comment.