Skip to content

Commit 3db31a7

Browse files
authored
Merge pull request #93 from smalleyes/master
修复可能存在的内存泄漏
2 parents b4f5729 + 87c61fa commit 3db31a7

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

book/chapt02/02-01-php-life-cycle-and-zend-engine.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ zend_shutdown将关闭Zend引擎。
249249
而ZEND_MODULE_DTOR宏对应的是module_destructor函数。
250250
在此函数中会调用模块的module_shutdown_func方法,即PHP_RSHUTDOWN_FUNCTION宏产生的那个函数。
251251

252-
在关闭所有的模块后,PHP继续销毁全局函数表,销毁全局类表、销售全局变量表等
252+
在关闭所有的模块后,PHP继续销毁全局函数表,销毁全局类表、销毁全局变量表等
253253
通过zend_shutdown_extensions遍历zend_extensions所有元素,调用每个扩展的shutdown函数。
254254

255255

book/chapt03/03-01-01-hashtable.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Bucket结构体是一个单链表,这是为了解决多个key哈希冲突的
162162
}
163163

164164
初始化的主要工作是为哈希表申请存储空间,函数中使用calloc函数的目的是确保
165-
数据存储的槽为都初始化为0,以便后续在插入和查找时确认该槽为是否被占用
165+
数据存储的槽位都初始化为0,以便后续在插入和查找时确认该槽位是否被占用
166166

167167
[c]
168168
int hash_insert(HashTable *ht, char *key, void *value)

book/chapt11/11-02-00-extension-hello-world.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ PHP 源代码目录中提供了一个可执行文件 `ext/ext_skel`,该文件
123123
char *result = NULL;
124124
char *prefix = "hello world, ";
125125

126-
127126
if (zend_parse_parameters(argc TSRMLS_CC, "s", &name, &name_len) == FAILURE)
128127
return;
129128

130129
result = (char *) ecalloc(strlen(prefix) + name_len + 1, sizeof(char));
131130
strncat(result, prefix, strlen(prefix));
132131
strncat(result, name, name_len);
133132

134-
RETURN_STRING(result);
133+
ZVAL_STRING(return_value, result);
134+
efree(result);
135135
}
136136

137137
其中 `zend_parse_parameters` 从我们在原型中定义的参数 `name` 中获取传入的字符串,分配内存之后保存在指针 `*name`中, `name_len` 为传入字符串的长度。

book/sample/chapt11/11-02-00-tipi-hello-world/tipi_demo01.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ PHP_FUNCTION(tipi_hello_world)
8383
char *result = NULL;
8484
char *prefix = "hello world, ";
8585

86-
8786
if (zend_parse_parameters(argc TSRMLS_CC, "s", &name, &name_len) == FAILURE)
8887
return;
8988

9089
result = (char *) ecalloc(strlen(prefix) + name_len + 1, sizeof(char));
9190
strncat(result, prefix, strlen(prefix));
9291
strncat(result, name, name_len);
9392

94-
RETURN_STRING(result);
93+
ZVAL_STRING(return_value, result);
94+
efree(result);
9595
}
9696
/* }}} */
9797

0 commit comments

Comments
 (0)