Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Commit

Permalink
check memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
h4child committed Mar 30, 2018
1 parent 8f074bc commit 227e708
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/framebot.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ Framebot *get_updates (Bot *bot, Framebot *framebot, long int offset, long int l
offset, limit, timeout, IF_STRING_NULL(allowed_updates) );

if( !framebot ){
framebot = (Framebot *)calloc(1, sizeof( Framebot ));
framebot = calloc(1, sizeof( Framebot ));
}

if(!s_json){
return framebot;
}


size_t length, i;
length = json_array_size(s_json->content);
if(length == 0){
close_json(s_json);
return framebot;
}

for (i = 0; i < length; i++) {
up = update_parse(json_array_get(s_json->content, i));
Expand Down
1 change: 1 addition & 0 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ MemStore * call_method_upload(const char * token, IFile ifile){
/* always cleanup */
curl_easy_cleanup(curl);

free(url);
/* then cleanup the form */
curl_mime_free(form);

Expand Down
3 changes: 2 additions & 1 deletion src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ Document *document(const char *file_id,PhotoSize *thumb, const char *file_name,

void document_free(Document *document){
free(document->file_id);
photo_size_free(document->thumb);
if(document->thumb)
photo_size_free(document->thumb);
free(document->file_name);
free(document->mime_type);
free(document);
Expand Down
22 changes: 22 additions & 0 deletions test/test_senddocument.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int _document(){
result = send_document_chat(_bot, chat_id, filename, NULL, 0, 0, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
message_free(result);
}
else{
Error *error = get_error();
Expand All @@ -51,6 +52,7 @@ int _document(){
result = send_document_chat(_bot, chat_id, filename, NULL, 0, 0, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
message_free(result);
}
else{
Error *error = get_error();
Expand All @@ -63,6 +65,7 @@ int _document(){
result = send_document_chat(_bot, chat_id, filename, "caption", 0, 0, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
message_free(result);
}
else{
Error *error = get_error();
Expand All @@ -87,6 +90,8 @@ int _document(){
Message * forward = send_document_chat(_bot, chat_id, filename, "caption", 1, result->message_id, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
message_free(result);
message_free(forward);
}
else{
Error *error = get_error();
Expand All @@ -97,6 +102,20 @@ int _document(){
return 0;
}

void _free(Framebot *update){
Update * m = NULL, *n = NULL;

m = update->up_message;
framebot_free(update);

while(m){
n = m->next;
update_free(m);
m = n;
}
}


int main(int argc, char *argv[]){
framebot_init();

Expand Down Expand Up @@ -125,8 +144,11 @@ int main(int argc, char *argv[]){
_document();
break;
}
update->up_message = update->up_message->next;
}

_free(update);

if(valid_username == 0)
printf("Username not found");

Expand Down

0 comments on commit 227e708

Please sign in to comment.