Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various static analyzer fixes #104

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/libsmbios_c/memory/memory_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ struct memory_access_obj *memory_obj_factory(int flags, ...)

// init_mem_* functions are responsible for free-ing memory if they return
// failure
toReturn->initialized = 0;
toReturn = 0;

out:
Expand Down
57 changes: 24 additions & 33 deletions src/libsmbios_c/smbios/smbios_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,65 +98,56 @@ int __hidden smbios_get_table_firm_tables(struct smbios_table *m)
dirname = m->table_path;

if (asprintf(&entry_fname, "%s/smbios_entry_point", dirname) < 0)
goto out_err;
goto done;
fnprintf("Using %s for entry point\n", entry_fname);

if (asprintf(&dmi_fname, "%s/DMI", dirname) < 0)
goto out_free_entry_path;
goto done;
fnprintf("Using %s for DMI\n", dmi_fname);

fnprintf("\n");
retval = -1;

if (read_file(entry_fname, 5, &entry_buffer, &entry_length))
goto out_free_dmi_path;
goto done;

error = _("Invalid SMBIOS table signature");
/* parse SMBIOS structure */
if (memcmp (entry_buffer, "_SM_", 4) == 0) {
if (!smbios_verify_smbios (entry_buffer, entry_length, &m->table_length))
goto out_free_entry_buffer;
goto done;
/* parse SMBIOS 3.0 structure */
} else if (memcmp (entry_buffer, "_SM3_", 5) == 0) {
if (!smbios_verify_smbios3 (entry_buffer, entry_length, &m->table_length))
goto out_free_entry_buffer;
goto done;
} else
goto out_free_entry_buffer;
goto done;

error = _("Could not read table from memory. ");
m->table = (struct table*)calloc(1, m->table_length);
if (!m->table)
goto out_free_entry_buffer;
goto done;

retval = read_file(dmi_fname, m->table_length, (char**) &m->table, &m->table_length);
if (retval)
goto out_free_table;
goto out;

out_free_table:
fnprintf(" out_free_table\n");
free(m->table);
m->table = 0;

out_free_entry_buffer:
free(entry_buffer);

out_free_dmi_path:
free(dmi_fname);
if (retval) {
fnprintf(" out_free_table\n");
free(m->table);
m->table = 0;
goto done;
}

out_free_entry_path:
retval = 0;
done:
free(entry_fname);

out_err:
fnprintf(" out_err\n");
if (strlen(m->errstring))
strlcat(m->errstring, "\n", ERROR_BUFSIZE);
strlcat (m->errstring, error, ERROR_BUFSIZE);
return retval;

out:
free(dmi_fname);
free(entry_buffer);
fnprintf(" out: %d\n", retval);
if (retval) {
fnprintf(" out_err\n");
if (strlen(m->errstring))
strlcat(m->errstring, "\n", ERROR_BUFSIZE);
strlcat (m->errstring, error, ERROR_BUFSIZE);
} else {
fnprintf(" out: %d\n", retval);
}
return retval;
}

Expand Down
3 changes: 2 additions & 1 deletion src/libsmbios_c/smbios/smbios_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ int __hidden init_smbios_struct(struct smbios_table *m)
if (m->errstring)
strlcat(errbuf, m->errstring, ERROR_BUFSIZE);
}
smbios_table_free(m);
if (m != &singleton)
smbios_table_free(m);
return -1;
}

Expand Down