Blame SOURCES/redhat-bugzilla-2029301.patch

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