memory leak?
メンテナーはふだん 12 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
提供されている create_monitor_with_helpers デモから始め、malloc_stats() を観察しながらループを再現します。cJSON オブジェクト、生成された文字列、繰り返し行われるアロケーションについて、所有権とクリーンアップを追跡し、その後、繰り返しの各イテレーションで使用中のバイト数を比較します。原因が特定され、修正が再現可能なメモリ結果で検証されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I write a demo test using cjson:
creating json object with array, the array size is rand, code is as follow.
i run the code, check heap size real-time, but i found,
in use bytes is increasing never decrease,
is memory leak? or i am wrong? any help, thanks!
`
/*
- cJSON test examples
*/
#include <stdio.h>
#include <stdlib.h>
#include "cJSON.h"
#include <malloc.h>
#include <string.h>
#include <unistd.h>
//NOTE: Returns a heap allocated string, you are required to free it after use.
char *create_monitor_with_helpers(void)
{
const unsigned int resolution_numbers[3][2] = {
{1280, 720},
{1920, 1080},
{3840, 2160}
};
char *string = NULL;
cJSON *resolutions = NULL;
size_t index = 0;
cJSON *monitor = cJSON_CreateObject();
if (cJSON_AddStringToObject(monitor, "name", "Awesome 4K") == NULL)
{
goto end;
}
resolutions = cJSON_AddArrayToObject(monitor, "resolutions");
if (resolutions == NULL)
{
goto end;
}
int N = 1000;
int value = rand() % (N + 1);
printf("rand value %d\n", value);
//for (index = 0; index < (sizeof(resolution_numbers) / (2 * sizeof(int))); ++index)
for (index = 0; index < value ; ++index)
{
cJSON *resolution = cJSON_CreateObject();
if (cJSON_AddNumberToObject(resolution, "width", value) == NULL)
{
goto end;
}
if (cJSON_AddNumberToObject(resolution, "height", value) == NULL)
{
goto end;
}
cJSON_AddItemToArray(resolutions, resolution);
}
string = cJSON_Print(monitor);
if (string == NULL)
{
fprintf(stderr, "Failed to print monitor.\n");
}
end:
cJSON_Delete(monitor);
return string;
}
/*
-
Main
/
int main() {
char out;while(1){
malloc_stats();out = create_monitor_with_helpers(); printf("packing %ld char string\n", strlen(out)); //printf("%s",out); free(out); sleep(1);}
return 0;
}
`
runing about 5 minute, malloc_stats() output increasing to as follow:
Arena 0:
system bytes = 704512
in use bytes = 92304
Total (incl. mmap):
system bytes = 704512
in use bytes = 92304
max mmap regions = 0
max mmap bytes = 0
about 90K byte.
- 主要言語
- C
- スター
- 13k
- フォーク
- 3.5k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
DaveGamble/cJSON のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DaveGamble/cJSON#1106 ·
メンテナーはふだん 12 日以内に返信
-
Undefined-Behavior in function cJSON_SetNumberHelper対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
DaveGamble/cJSON#1100 · リアクション 1 件 ·
メンテナーはふだん 12 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
DaveGamble/cJSON#1094 · コメント 9 件 · リアクション 1 件 ·
メンテナーはふだん 12 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DaveGamble/cJSON#1093 ·
メンテナーはふだん 12 日以内に返信
-
Use-after-free in cJSONUtils_ApplyPatches when a patch removes the patch array対応中かも @iliasabk が 30 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
DaveGamble/cJSON#1082 ·
メンテナーはふだん 12 日以内に返信
DaveGamble/cJSON の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
FujiNetWIFI/fujinet-firmware#2079 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
VirusTotal/yara#2255 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
-
state:needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
zed-industries/zed#65836 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
neutralinojs/neutralinojs#1861 ·
メンテナーはふだん 1 日以内に返信