Blame SOURCES/redhat-bugzilla-2029301.patch

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