]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/names-parse.c
RCD: Cleanup
[pciutils.git] / lib / names-parse.c
index 71b622f84cb841d5a85274a9ecf17dbbea6e18a5..1f8925a34f44856c161e0a0b89456518d2bf8ee0 100644 (file)
@@ -3,7 +3,9 @@
  *
  *     Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
  *
- *     Can be freely distributed and used under the terms of the GNU GPL.
+ *     Can be freely distributed and used under the terms of the GNU GPL v2+.
+ *
+ *     SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include <stdio.h>
@@ -30,7 +32,7 @@ static pci_file pci_open(struct pci_access *a)
   if (result)
     return result;
   len = strlen(a->id_file_name);
-  if (len >= 3 && memcmp(a->id_file_name + len - 3, ".gz", 3) != 0)
+  if (len < 3 || memcmp(a->id_file_name + len - 3, ".gz", 3) != 0)
     return result;
   new_name = malloc(len - 2);
   memcpy(new_name, a->id_file_name, len - 3);
@@ -42,7 +44,7 @@ static pci_file pci_open(struct pci_access *a)
 #define pci_close(f)           gzclose(f)
 #define PCI_ERROR(f, err)                                              \
        if (!err) {                                                     \
-               int errnum;                                             \
+               int errnum = 0;                                         \
                gzerror(f, &errnum);                                    \
                if (errnum >= 0) err = NULL;                            \
                else if (errnum == Z_ERRNO) err = "I/O error";          \
@@ -221,7 +223,7 @@ pci_load_name_list(struct pci_access *a)
   const char *err;
 
   pci_free_name_list(a);
-  a->id_load_failed = 1;
+  a->id_load_attempted = 1;
   if (!(f = pci_open(a)))
     return 0;
   err = id_parse_list(a, f, &lino);
@@ -229,11 +231,20 @@ pci_load_name_list(struct pci_access *a)
   pci_close(f);
   if (err)
     a->error("%s at %s, line %d\n", err, a->id_file_name, lino);
-  a->id_load_failed = 0;
   return 1;
 }
 
-void pci_set_name_list_path(struct pci_access *a, char *name, int to_be_freed)
+void
+pci_free_name_list(struct pci_access *a)
+{
+  pci_id_cache_flush(a);
+  pci_id_hash_free(a);
+  pci_id_hwdb_free(a);
+  a->id_load_attempted = 0;
+}
+
+void
+pci_set_name_list_path(struct pci_access *a, char *name, int to_be_freed)
 {
   if (a->free_id_name)
     free(a->id_file_name);