瀏覽代碼

Merge pull request #647 from smititelu/master

mem: Add on-error log messages for q_/f_ functions
Daniel-Constantin Mierla 9 年之前
父節點
當前提交
d403c666eb
共有 2 個文件被更改,包括 30 次插入0 次删除
  1. 15 0
      mem/f_malloc.c
  2. 15 0
      mem/q_malloc.c

+ 15 - 0
mem/f_malloc.c

@@ -336,6 +336,7 @@ struct fm_block* fm_malloc_init(char* address, unsigned long size, int type)
 	if (size < init_overhead)
 	{
 		/* not enough mem to create our control structures !!!*/
+		LOG(L_ERR, "fm_malloc_init(%lu); No memory left to create control structures!\n", size);
 		return 0;
 	}
 	end=start+size;
@@ -409,6 +410,8 @@ struct fm_frag* fm_search_defrag(struct fm_block* qm, unsigned long size)
 		frag = nxt;
 	}
 
+	LOG(L_ERR, "fm_search_defrag(%p, %lu); Free fragment not found!\n", qm, size);
+
 	return 0;
 }
 
@@ -488,6 +491,12 @@ void* fm_malloc(void* qmp, unsigned long size)
 
 	if(frag) goto finish;
 
+#ifdef DBG_F_MALLOC
+        LOG(L_ERR, "fm_malloc(%p, %lu) called from %s: %s(%d), module: %s; Free fragment not found!\n", qm, size, file, func, line, mname);
+#else
+        LOG(L_ERR, "fm_malloc(%p, %lu); Free fragment not found!\n", qm, size);
+#endif
+
 	return 0;
 
 found:
@@ -715,6 +724,12 @@ void* fm_realloc(void* qmp, void* p, unsigned long size)
 			if (ptr){
 				/* copy, need by libssl */
 				memcpy(ptr, p, orig_size);
+			} else {
+#ifdef DBG_F_MALLOC
+				LOG(L_ERR, "fm_realloc(%p, %lu) called from %s: %s(%d), module: %s; fm_malloc() failed!\n", qm, size, file, func, line, mname);
+#else
+				LOG(L_ERR, "fm_realloc(%p, %lu); fm_malloc() failed!\n", qm, size);
+#endif
 			}
 	#ifdef DBG_F_MALLOC
 			fm_free(qm, p, file, func, line, mname);

+ 15 - 0
mem/q_malloc.c

@@ -202,6 +202,7 @@ struct qm_block* qm_malloc_init(char* address, unsigned long size, int type)
 	if (size < init_overhead)
 	{
 		/* not enough mem to create our control structures !!!*/
+		LOG(L_ERR, "qm_malloc_init(%lu); No memory left to create control structures!\n", size);
 		return 0;
 	}
 	end=start+size;
@@ -285,6 +286,7 @@ static inline struct qm_frag* qm_find_free(struct qm_block* qm,
 	/*try in a bigger bucket*/
 	}
 	/* not found */
+	LOG(L_ERR, "qm_find_free(%p, %lu); Free fragment not found!\n", qm, size);
 	return 0;
 }
 
@@ -413,6 +415,13 @@ void* qm_malloc(void* qmp, unsigned long size)
 #endif
 		return (char*)f+sizeof(struct qm_frag);
 	}
+
+#ifdef DBG_QM_MALLOC
+	LOG(L_ERR, "qm_malloc(%p, %lu) called from %s: %s(%d), module: %s; Free fragment not found!\n", qm, size, file, func, line, mname);
+#else
+	LOG(L_ERR, "qm_malloc(%p, %lu); Free fragment not found!\n", qm, size);
+#endif
+
 	return 0;
 }
 
@@ -653,6 +662,12 @@ void* qm_realloc(void* qmp, void* p, unsigned long size)
 				if (ptr){
 					/* copy, need by libssl */
 					memcpy(ptr, p, orig_size);
+				} else {
+#ifdef DBG_QM_MALLOC
+					LOG(L_ERR, "qm_realloc(%p, %lu) called from %s: %s(%d), module: %s; qm_malloc() failed!\n", qm, size, file, func, line, mname);
+#else
+					LOG(L_ERR, "qm_realloc(%p, %lu); qm_malloc() failed!\n", qm, size);
+#endif
 				}
 	#ifdef DBG_QM_MALLOC
 				qm_free(qm, p, file, func, line, mname);