fix leak of utsname structure (coverity 1109881)

This commit is contained in:
Vincent Sanders 2013-11-06 10:53:01 +00:00
parent 8702eedf67
commit f8854707bb
1 changed files with 16 additions and 13 deletions

View File

@ -95,22 +95,25 @@ getter language %{
%}
getter platform %{
struct utsname *cutsname;
struct utsname *cutsname;
cutsname = malloc(sizeof(struct utsname));
cutsname = malloc(sizeof(struct utsname));
if ((cutsname != NULL) && (uname(cutsname) >= 0)) {
char *platstr;
int platstrlen;
if (cutsname != NULL) {
if (uname(cutsname) >= 0) {
char *platstr;
int platstrlen;
platstrlen = strlen(cutsname->sysname) + strlen(cutsname->machine) + 2;
platstr = malloc(platstrlen);
if (platstr != NULL) {
snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine);
jsret = JS_NewStringCopyN(cx, platstr, platstrlen - 1);
free(platstr);
}
}
platstrlen = strlen(cutsname->sysname) + strlen(cutsname->machine) + 2;
platstr = malloc(platstrlen);
if (platstr != NULL) {
snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine);
jsret = JS_NewStringCopyN(cx, platstr, platstrlen - 1);
free(platstr);
}
}
free(cutsname);
}
%}
getter userAgent %{