Blame SOURCES/redhat-bugzilla-2029301.patch

f76dca
commit 9d9adc9d6c8eb24a6884da81c18b927ea706a68e
f76dca
Author: Nathan Scott <nathans@redhat.com>
f76dca
Date:   Tue Dec 7 11:18:11 2021 +1100
f76dca
f76dca
    pmdanvidia: fix mishandling of zero-byte size passed to realloc
f76dca
    
f76dca
    Picked up during QA of recent nvidia changes - some hardware lacks
f76dca
    support for per-process metrics, or the hardware (GPU) has not yet
f76dca
    been accessed by a process using its resources, which had the side
f76dca
    effect that a zero-byte size argument was passed into realloc.  In
f76dca
    turn, this passes back something that can be freed and an issue in
f76dca
    the logic meant this would happen on subsequent calls also.
f76dca
    
f76dca
    Resolves the QA failure and Red Hat BZ #2029301
f76dca
f76dca
diff --git a/src/pmdas/nvidia/nvidia.c b/src/pmdas/nvidia/nvidia.c
f76dca
index f1c12f2275..dc5bb93a0d 100644
f76dca
--- a/src/pmdas/nvidia/nvidia.c
f76dca
+++ b/src/pmdas/nvidia/nvidia.c
f76dca
@@ -617,11 +617,16 @@ refresh(pcp_nvinfo_t *nvinfo, int need_processes)
f76dca
     /* update indoms, cull old entries that remain inactive */
f76dca
     if (need_processes) {
f76dca
 	pmdaIndom	*proc_indomp = &indomtab[PROC_INDOM];
f76dca
-	pmdaInstid	*it_set = proc_indomp->it_set;
f76dca
+	pmdaInstid	*it_set = NULL;
f76dca
 	size_t		bytes = nproc * sizeof(pmdaInstid);
f76dca
 
f76dca
-	if ((it_set = (pmdaInstid *)realloc(it_set, bytes)) == NULL)
f76dca
+	if (bytes > 0) {
f76dca
+	    it_set = (pmdaInstid *)realloc(proc_indomp->it_set, bytes);
f76dca
+	    if (it_set == NULL)
f76dca
+		free(proc_indomp->it_set);
f76dca
+	} else if (proc_indomp->it_set != NULL) {
f76dca
 	    free(proc_indomp->it_set);
f76dca
+	}
f76dca
 
f76dca
 	if ((proc_indomp->it_set = it_set) != NULL) {
f76dca
 	    for (i = j = 0; i < processes.hsize && j < nproc; i++) {