Browse code

- *_realloc bug fix: on grow, when out of memory, realloc would free the original pointer (instead of leaving it alone and just returning null)

Andrei Pelinescu-Onciul authored on 03/02/2006 21:06:44
Showing 2 changed files
... ...
@@ -36,6 +36,7 @@
36 36
  *  2005-03-02  added fm_info() (andrei)
37 37
  *  2005-12-12  fixed realloc shrink real_used accounting (andrei)
38 38
  *              fixed initial size (andrei)
39
+ *  2006-02-03  fixed realloc out of mem. free bug (andrei)
39 40
  */
40 41
 
41 42
 
... ...
@@ -456,7 +457,7 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
456 456
 	#else
457 457
 			ptr=fm_malloc(qm, size);
458 458
 	#endif
459
-			if (ptr)
459
+			if (ptr){
460 460
 				/* copy, need by libssl */
461 461
 				memcpy(ptr, p, orig_size);
462 462
 	#ifdef DBG_F_MALLOC
... ...
@@ -464,8 +465,9 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
464 464
 	#else
465 465
 				fm_free(qm, p);
466 466
 	#endif
467
-				p=ptr;
468 467
 			}
468
+			p=ptr;
469
+		}
469 470
 	}else{
470 471
 		/* do nothing */
471 472
 #ifdef DBG_F_MALLOC
... ...
@@ -37,6 +37,7 @@
37 37
  *  2005-03-02  added qm_info() (andrei)
38 38
  *  2005-12-12  fixed realloc shrink real_used & used accounting;
39 39
  *              fixed initial size (andrei)
40
+ *  2006-02-03  fixed realloc out of mem. free bug (andrei)
40 41
  */
41 42
 
42 43
 
... ...
@@ -599,7 +600,7 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
599 599
 	#else
600 600
 				ptr=qm_malloc(qm, size);
601 601
 	#endif
602
-				if (ptr)
602
+				if (ptr){
603 603
 					/* copy, need by libssl */
604 604
 					memcpy(ptr, p, orig_size);
605 605
 	#ifdef DBG_QM_MALLOC
... ...
@@ -607,6 +608,7 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
607 607
 	#else
608 608
 					qm_free(qm, p);
609 609
 	#endif
610
+				}
610 611
 				p=ptr;
611 612
 			}
612 613
 	}else{