Bläddra i källkod

- *_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 19 år sedan
förälder
incheckning
9b1c8956bc
2 ändrade filer med 7 tillägg och 3 borttagningar
  1. 4 2
      mem/f_malloc.c
  2. 3 1
      mem/q_malloc.c

+ 4 - 2
mem/f_malloc.c

@@ -36,6 +36,7 @@
  *  2005-03-02  added fm_info() (andrei)
  *  2005-12-12  fixed realloc shrink real_used accounting (andrei)
  *              fixed initial size (andrei)
+ *  2006-02-03  fixed realloc out of mem. free bug (andrei)
  */
 
 
@@ -456,7 +457,7 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
 	#else
 			ptr=fm_malloc(qm, size);
 	#endif
-			if (ptr)
+			if (ptr){
 				/* copy, need by libssl */
 				memcpy(ptr, p, orig_size);
 	#ifdef DBG_F_MALLOC
@@ -464,8 +465,9 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
 	#else
 				fm_free(qm, p);
 	#endif
-				p=ptr;
 			}
+			p=ptr;
+		}
 	}else{
 		/* do nothing */
 #ifdef DBG_F_MALLOC

+ 3 - 1
mem/q_malloc.c

@@ -37,6 +37,7 @@
  *  2005-03-02  added qm_info() (andrei)
  *  2005-12-12  fixed realloc shrink real_used & used accounting;
  *              fixed initial size (andrei)
+ *  2006-02-03  fixed realloc out of mem. free bug (andrei)
  */
 
 
@@ -599,7 +600,7 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
 	#else
 				ptr=qm_malloc(qm, size);
 	#endif
-				if (ptr)
+				if (ptr){
 					/* copy, need by libssl */
 					memcpy(ptr, p, orig_size);
 	#ifdef DBG_QM_MALLOC
@@ -607,6 +608,7 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
 	#else
 					qm_free(qm, p);
 	#endif
+				}
 				p=ptr;
 			}
 	}else{