@@ -184,19 +184,12 @@ crt_bulk_addref(crt_bulk_t crt_bulk)
184184{
185185 struct crt_bulk * bulk = crt_bulk ;
186186 int rc = - DER_SUCCESS ;
187- hg_return_t hg_ret ;
188187
189188 if (bulk == NULL ) {
190189 D_ERROR ("invalid parameter, NULL bulk\n" );
191190 D_GOTO (out , rc = - DER_INVAL );
192191 }
193192
194- hg_ret = HG_Bulk_ref_incr (bulk -> hg_bulk_hdl );
195- if (hg_ret != HG_SUCCESS ) {
196- D_ERROR ("HG_Bulk_ref_incr failed, hg_ret: %d.\n" , hg_ret );
197- rc = crt_hgret_2_der (hg_ret );
198- }
199-
200193 atomic_fetch_add (& bulk -> refcount , 1 );
201194out :
202195 return rc ;
@@ -206,43 +199,43 @@ int
206199crt_bulk_free (crt_bulk_t crt_bulk )
207200{
208201 struct crt_bulk * bulk = crt_bulk ;
209- int rc = - DER_SUCCESS ;
210- hg_return_t hg_ret ;
211202
212203 if (bulk == NULL ) {
213204 D_ERROR ("invalid parameter, NULL bulk\n" );
214- D_GOTO (out , rc = - DER_INVAL );
215- }
216-
217- /* This can happen if D_QUOTA_BULKS is enabled on a client */
218- if (bulk -> hg_bulk_hdl == HG_BULK_NULL ) {
219- if (bulk -> deferred ) {
220- /* Treat as success */
221- D_GOTO (out , rc = DER_SUCCESS );
222- } else {
223- D_ASSERTF (0 , "Bulk handle should not be NULL\n" );
224- }
225- }
226-
227- hg_ret = HG_Bulk_free (bulk -> hg_bulk_hdl );
228- if (hg_ret != HG_SUCCESS ) {
229- D_ERROR ("HG_Bulk_free failed, hg_ret: %d.\n" , hg_ret );
230- rc = crt_hgret_2_der (hg_ret );
205+ return - DER_INVAL ;
231206 }
232207
233208 if (atomic_fetch_sub (& bulk -> refcount , 1 ) > 1 )
234209 return DER_SUCCESS ;
235210
211+ crt_bulk_free_common (bulk );
212+
213+ return DER_SUCCESS ;
214+ }
215+
216+ void
217+ crt_bulk_free_common (struct crt_bulk * bulk )
218+ {
219+ hg_return_t hg_ret ;
220+
221+ D_ASSERT (bulk != NULL );
222+
223+ /* Decrement refcount on bulk handle itself */
224+ if (bulk -> hg_bulk_hdl != HG_BULK_NULL ) {
225+ hg_ret = HG_Bulk_free (bulk -> hg_bulk_hdl );
226+ if (hg_ret != HG_SUCCESS ) {
227+ D_ERROR ("HG_Bulk_free() failed (%s)\n" , HG_Error_to_string (hg_ret ));
228+ /* Ignore the error, as we are already in a cleanup path */
229+ }
230+ }
231+
236232 /* decoded bulks are not counted towards quota; such bulks have crt_ctx set to NULL */
237- if (bulk -> crt_ctx )
233+ if (! bulk -> deferred && bulk -> crt_ctx != NULL )
238234 put_quota_resource (bulk -> crt_ctx , CRT_QUOTA_BULKS );
239- out :
240- if (bulk != NULL ) {
241- if (bulk -> iovs )
242- D_FREE (bulk -> iovs );
243- D_FREE (bulk );
244- }
245- return rc ;
235+
236+ if (bulk -> iovs != NULL )
237+ D_FREE (bulk -> iovs );
238+ D_FREE (bulk );
246239}
247240
248241/* Helper function to check for bulk expiration */
0 commit comments