Browse Source

Ticket #47774 mem leak in do_search - rawbase not freed upon certain errors

https://fedorahosted.org/389/ticket/47774
Reviewed by: nhosoi (Thanks!)
Branch: master
Fix Description: Free the local rawbase variable if it was not set in the
pblock.
Platforms tested: RHEL6 x86_64
Flag Day: no
Doc impact: no
Rich Megginson 11 năm trước cách đây
mục cha
commit
1d5c6d6ca3
1 tập tin đã thay đổi với 5 bổ sung1 xóa
  1. 5 1
      ldap/servers/slapd/search.c

+ 5 - 1
ldap/servers/slapd/search.c

@@ -69,6 +69,7 @@ do_search( Slapi_PBlock *pb )
 	int			i, err, attrsonly;
 	ber_int_t		scope, deref, sizelimit, timelimit;
 	char		*rawbase = NULL;
+	int             rawbase_set_in_pb = 0; /* was rawbase set in pb? */
 	char		*base = NULL, *fstr = NULL;
 	struct slapi_filter	*filter = NULL;
 	char		**attrs = NULL;
@@ -360,6 +361,7 @@ do_search( Slapi_PBlock *pb )
 	}
 
 	slapi_pblock_set( pb, SLAPI_ORIGINAL_TARGET_DN, rawbase );
+	rawbase_set_in_pb = 1; /* rawbase is now owned by pb */
 	slapi_pblock_set( pb, SLAPI_SEARCH_SCOPE, &scope );
 	slapi_pblock_set( pb, SLAPI_SEARCH_DEREF, &deref );
 	slapi_pblock_set( pb, SLAPI_SEARCH_FILTER, filter );
@@ -397,7 +399,9 @@ free_and_return:;
 			operation->o_flags &= ~OP_FLAG_PS;
 		}
 		/* we strdup'd this above - need to free */
-		slapi_pblock_get(pb, SLAPI_ORIGINAL_TARGET_DN, &rawbase);
+		if (rawbase_set_in_pb) {
+			slapi_pblock_get(pb, SLAPI_ORIGINAL_TARGET_DN, &rawbase);
+		}
 		slapi_ch_free_string(&rawbase);
 	}
 }