Jelajahi Sumber

Ticket #48905 - coverity defects

(1) Clang warning.
    ldap/servers/slapd/util.c:1631:20: warning: Dereference of null
    pointer (loaded from variable 'procpages')
    Fix Description - Changed to check if procpages as well as other
    arguments to return values are NULL or not first.  If any of them
    is NULL, the function returns failure.

(2) Resource Leaks.
    ldap/servers/plugins/replication/repl5_tot_protocol.c:616:
    leaked_storage: Variable "pb" going out of scope leaks the storage
    it points to.
    Fix Description - Moved "lapi_pblock_destroy(pb)" to the location
    next to the "done" label so that it is guaranteed that "pb" is
    destroyed when the function returns.
Noriko Hosoi 9 tahun lalu
induk
melakukan
0ef4adbc6b

+ 2 - 2
ldap/servers/plugins/replication/repl5_tot_protocol.c

@@ -314,7 +314,7 @@ repl5_tot_run(Private_Repl_Protocol *prp)
 {
     int rc;
     callback_data cb_data = {0};
-    Slapi_PBlock *pb;
+    Slapi_PBlock *pb = NULL;
     LDAPControl **ctrls;
 	char *hostname = NULL;
 	int portnum = 0;
@@ -575,7 +575,6 @@ retry:
 	 * suitable messages will have been logged to the error log about the failure.
 	 */
 
-	slapi_pblock_destroy (pb);
 	agmt_set_last_init_end(prp->agmt, current_time());
 	rc = cb_data.rc;
 	agmt_set_update_in_progress(prp->agmt, PR_FALSE);
@@ -595,6 +594,7 @@ retry:
 	}
 
 done:
+	slapi_pblock_destroy(pb);
 	slapi_sdn_free(&area_sdn);
 	slapi_ch_free_string(&hostname);
 	if (cb_data.flowcontrol_detection > 1)

+ 7 - 3
ldap/servers/slapd/util.c

@@ -1500,18 +1500,22 @@ static size_t util_getvirtualmemsize()
  */
 int util_info_sys_pages(size_t *pagesize, size_t *pages, size_t *procpages, size_t *availpages)
 {
+    if ((NULL == pagesize) || (NULL == pages) || (NULL == procpages) || (NULL == availpages)) {
+        slapi_log_error(SLAPI_LOG_FATAL, "util_info_sys_pages",
+                        "ERROR: Null return variables are passed.  Skip getting the system info.\n");
+        return 1;
+    }
     *pagesize = 0;
     *pages = 0;
     *availpages = 0;
-    if (procpages)
-        *procpages = 0;
+    *procpages = 0;
 
 #ifdef OS_solaris
     *pagesize = (int)sysconf(_SC_PAGESIZE);
     *pages = (int)sysconf(_SC_PHYS_PAGES);
     *availpages = util_getvirtualmemsize() / *pagesize;
     /* solaris has THE most annoying way to get this info */
-    if (procpages) {
+    {
         struct prpsinfo psi;
         char fn[40];
         int fd;