Skip to content

Commit 1344dc8

Browse files
authored
Merge branch 'master' into covscan_fix_part2
2 parents f2b53ca + bd25d10 commit 1344dc8

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

src/dmidecode.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void dmi_dump(xmlNode *node, struct dmi_header * h)
222222
for(row = 0; row < ((h->length - 1) >> 4) + 1; row++) {
223223
memset(tmp_s, 0, (h->length * 2) + 2);
224224

225-
for(i = 0; i < (16 && i < h->length - (row << 4)); i++) {
225+
for(i = 0; i < 16 && (i < h->length - (row << 4)); i++) {
226226
snprintf(tmp_s + strlen(tmp_s), (h->length * 2)-strlen(tmp_s),
227227
"0x%02x", (h->data)[(row << 4) + i]);
228228
}
@@ -1372,7 +1372,7 @@ void dmi_processor_upgrade(xmlNode *node, u8 code)
13721372
"Socket LGA1156",
13731373
"Socket LGA1567",
13741374
"Socket PGA988A",
1375-
"Socket BGA1288" /* 0x20 */
1375+
"Socket BGA1288", /* 0x20 */
13761376
"Socket rPGA988B",
13771377
"Socket BGA1023",
13781378
"Socket BGA1224",
@@ -1840,7 +1840,7 @@ void dmi_cache_associativity(xmlNode *node, u8 code)
18401840
"24-way Set-associative",
18411841
"32-way Set-associative",
18421842
"48-way Set-associative",
1843-
"64-way Set-associative" /* 0x0D */
1843+
"64-way Set-associative", /* 0x0D */
18441844
"20-way Set-associative" /* 0x0E */
18451845
};
18461846
xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Associativity", NULL);
@@ -2865,7 +2865,7 @@ void dmi_memory_device_type(xmlNode *node, u8 code)
28652865
"Reserved",
28662866
"Reserved",
28672867
"Reserved",
2868-
"DDR3"
2868+
"DDR3",
28692869
"FBD2" /* 0x19 */
28702870
};
28712871
xmlNode *data_n = xmlNewChild(node, NULL, (xmlChar *) "Type", NULL);

src/dmierror.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ void _pyReturnError(void *exception, const char *fname, int line, const char *fm
5252

5353
va_start(ap, fmt);
5454
buf = (char *) malloc(4098);
55-
memset(buf, 0, 4098);
5655

5756
if( buf == NULL ) {
5857
// Backup routine if we can't get the needed memory
@@ -64,6 +63,7 @@ void _pyReturnError(void *exception, const char *fname, int line, const char *fm
6463
return;
6564
}
6665

66+
memset(buf, 0, 4098);
6767
// Set the error state and message
6868
snprintf(buf, 4096, "[%s:%i] %s", fname, line, fmt);
6969
PyErr_Format(exception, buf, ap);

src/dmilog.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Log_t * log_init()
4747
ret = (Log_t *) calloc(1, sizeof(Log_t)+2);
4848
if( !ret ) {
4949
fprintf(stderr, "** ERROR ** Could not allocate memory for log data\n");
50+
return ret;
5051
}
5152
ret->level = -1; // Initialised - chain header pointer always have -1.
5253
return ret;

src/util.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void sigill_handler(int ignore_this) {
112112
void *mem_chunk(Log_t *logp, size_t base, size_t len, const char *devmem)
113113
{
114114
void *p;
115-
int fd;
115+
int fd = -1;
116116

117117
#ifdef USE_MMAP
118118
size_t mmoffset;
@@ -182,10 +182,11 @@ void *mem_chunk(Log_t *logp, size_t base, size_t len, const char *devmem)
182182
}
183183
#endif /* USE_MMAP */
184184

185-
if(close(fd) == -1)
186-
perror(devmem);
187-
188185
exit:
186+
if (fd >= 0) {
187+
if(close(fd) == -1)
188+
perror(devmem);
189+
}
189190
signal(SIGILL, SIG_DFL);
190191
sigill_logobj = NULL;
191192
return p;

src/xmlpythonizer.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,9 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
854854
value = PyBytes_FromString(map_p->value);
855855
PyADD_DICT_VALUE(retdata, key, value);
856856
} else {
857+
xmlXPathFreeContext(xpctx);
858+
xmlFreeDoc(xpdoc);
859+
free(key);
857860
PyReturnError(PyExc_ValueError, "Could not get key value: %s [%i] (Defining key: %s)",
858861
map_p->rootpath, elmtid, map_p->key);
859862
}
@@ -918,6 +921,10 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
918921
PyADD_DICT_VALUE(retdata, key, value);
919922
xmlXPathFreeObject(xpo);
920923
} else {
924+
xmlXPathFreeObject(xpo);
925+
xmlXPathFreeContext(xpctx);
926+
xmlFreeDoc(xpdoc);
927+
free(key);
921928
PyReturnError(PyExc_ValueError, "Could not get key value: "
922929
"%s [%i] (Defining key: %s)",
923930
map_p->rootpath, elmtid, map_p->key);
@@ -931,6 +938,9 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
931938
break;
932939
}
933940
if( _get_key_value(logp, key, 256, map_p, xpctx, 0) == NULL ) {
941+
xmlXPathFreeContext(xpctx);
942+
xmlFreeDoc(xpdoc);
943+
free(key);
934944
PyReturnError(PyExc_ValueError,
935945
"Could not get key value: %s [%i] (Defining key: %s)",
936946
map_p->rootpath, elmtid, map_p->key);
@@ -945,6 +955,9 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
945955
break;
946956
}
947957
if( _get_key_value(logp, key, 256, map_p, xpctx, 0) == NULL ) {
958+
xmlXPathFreeContext(xpctx);
959+
xmlFreeDoc(xpdoc);
960+
free(key);
948961
PyReturnError(PyExc_ValueError,
949962
"Could not get key value: %s [%i] (Defining key: %s)",
950963
map_p->rootpath, elmtid, map_p->key);
@@ -956,6 +969,9 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
956969
if( xpo != NULL ) {
957970
xmlXPathFreeObject(xpo);
958971
}
972+
xmlXPathFreeContext(xpctx);
973+
xmlFreeDoc(xpdoc);
974+
free(key);
959975
PyReturnError(PyExc_ValueError,
960976
"Could not get key value: %s [%i] (Defining key: %s)",
961977
map_p->rootpath, elmtid, map_p->key);
@@ -991,6 +1007,10 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
9911007
PyList_Append(value, dataset);
9921008
}
9931009
} else {
1010+
xmlXPathFreeObject(xpo);
1011+
xmlXPathFreeContext(xpctx);
1012+
xmlFreeDoc(xpdoc);
1013+
free(key);
9941014
// If NULL, something is wrong - exception is already set.
9951015
return NULL;
9961016
}
@@ -1047,6 +1067,8 @@ PyObject *pythonizeXMLnode(Log_t *logp, ptzMAP *in_map, xmlNode *data_n) {
10471067

10481068
xpctx = xmlXPathNewContext(xpdoc);
10491069
if( xpctx == NULL ) {
1070+
xmlFreeDoc(xpdoc);
1071+
free(key);
10501072
PyReturnError(PyExc_MemoryError, "Could not setup new XPath context");
10511073
}
10521074
xpctx->node = data_n;
@@ -1062,6 +1084,10 @@ PyObject *pythonizeXMLnode(Log_t *logp, ptzMAP *in_map, xmlNode *data_n) {
10621084
if( res == NULL ) {
10631085
// Exit if we get NULL - something is wrong
10641086
//and exception is set
1087+
xmlXPathFreeObject(xpo);
1088+
xmlXPathFreeContext(xpctx);
1089+
xmlFreeDoc(xpdoc);
1090+
free(key);
10651091
return NULL;
10661092
}
10671093
}
@@ -1084,6 +1110,7 @@ PyObject *pythonizeXMLnode(Log_t *logp, ptzMAP *in_map, xmlNode *data_n) {
10841110
if( res == NULL ) {
10851111
// Exit if we get NULL - something is wrong
10861112
//and exception is set
1113+
free(key);
10871114
return NULL;
10881115
}
10891116
}

0 commit comments

Comments
 (0)