Browse Source

[slam] Fix resource leak on error path

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 years ago
parent
commit
60561d0f3d
1 changed files with 10 additions and 4 deletions
  1. 10
    4
      src/net/udp/slam.c

+ 10
- 4
src/net/udp/slam.c View File

266
 	if ( ! iobuf ) {
266
 	if ( ! iobuf ) {
267
 		DBGC ( slam, "SLAM %p could not allocate I/O buffer\n",
267
 		DBGC ( slam, "SLAM %p could not allocate I/O buffer\n",
268
 		       slam );
268
 		       slam );
269
-		return -ENOMEM;
269
+		rc = -ENOMEM;
270
+		goto err_alloc;
270
 	}
271
 	}
271
 
272
 
272
 	/* Construct NACK.  We always request only a single packet;
273
 	/* Construct NACK.  We always request only a single packet;
294
 		       "0-%ld\n", slam, ( num_blocks - 1 ) );
295
 		       "0-%ld\n", slam, ( num_blocks - 1 ) );
295
 	}
296
 	}
296
 	if ( ( rc = slam_put_value ( slam, iobuf, first_block ) ) != 0 )
297
 	if ( ( rc = slam_put_value ( slam, iobuf, first_block ) ) != 0 )
297
-		return rc;
298
+		goto err_put_value;
298
 	if ( ( rc = slam_put_value ( slam, iobuf, num_blocks ) ) != 0 )
299
 	if ( ( rc = slam_put_value ( slam, iobuf, num_blocks ) ) != 0 )
299
-		return rc;
300
+		goto err_put_value;
300
 	nul = iob_put ( iobuf, 1 );
301
 	nul = iob_put ( iobuf, 1 );
301
 	*nul = 0;
302
 	*nul = 0;
302
 
303
 
303
 	/* Transmit packet */
304
 	/* Transmit packet */
304
-	return xfer_deliver_iob ( &slam->socket, iobuf );
305
+	return xfer_deliver_iob ( &slam->socket, iob_disown ( iobuf ) );
306
+
307
+ err_put_value:
308
+	free_iob ( iobuf );
309
+ err_alloc:
310
+	return rc;
305
 }
311
 }
306
 
312
 
307
 /**
313
 /**

Loading…
Cancel
Save