Fix memory leaks

master
teknomunk 1 year ago
parent b7bef499e6
commit 83405b16d2

@ -31,6 +31,12 @@ bool handle_timeline( struct http_request* req, int timeline_id )
unsigned int limit = 100;
struct timeline* tl = timeline_from_id( timeline_id );
if( !tl ) {
http_request_send_headers( req, 200, "application/json", true );
FILE* f = http_request_get_response_body( req );
fprintf( f, "[]" );
return true;
}
struct status* ss[32];
int count = timeline_load_statuses( tl, 0, 32, ss );
@ -88,7 +94,6 @@ bool route_mastodon_api( struct http_request* req )
printf( "authorization still valid\n" );
//*/
struct account* owner = account_from_id(0);
if( http_request_route( req, "notifications" ) ) {
return handle_notifications(req);
@ -112,7 +117,10 @@ bool route_mastodon_api( struct http_request* req )
return true;
}
} else if( http_request_route_method( req, "POST" ) ) {
return handle_post(req, owner);
struct account* owner = account_from_id(0);
bool res = handle_post(req, owner);
account_free(owner);
return res;
}
} else if( http_request_route( req, "timelines/" ) ) {
if( http_request_route( req, "home" ) ) {
@ -139,12 +147,19 @@ bool route_mastodon_api( struct http_request* req )
if( !a ) { return false; }
if( http_request_route( req, "statuses" ) ) {
return handle_timeline( req, id );
bool res = handle_timeline( req, id );
account_free(a);
return res;
} else {
return handle_mastodon_api_show_account( req, a );
bool res = handle_mastodon_api_show_account( req, a );
account_free(a);
return res;
}
} else if( id == 0 ) {
return handle_mastodon_api_show_account( req, owner );
struct account* owner = account_from_id(0);
bool res = handle_mastodon_api_show_account( req, owner );
account_free(owner);
return res;
}
}

@ -1 +1 @@
Subproject commit 8f145d989b96f45fb37e80e26789891328fa7a5d
Subproject commit 2aa3a9ede60164ee3e28ffa1a8ed8cdd04ff6ee6

@ -1 +1 @@
Subproject commit 0f07cd429652690aba5a6dc8908072f75b1df03a
Subproject commit 2499319c2c357fe2bc7f2a340299fd17bfeca2b4

@ -364,6 +364,15 @@ struct account* account_fetch_from_uri( const char* uri )
void account_free( struct account* a )
{
if( !a ) { return; }
free(a->handle);
free(a->server);
free(a->display_name);
free(a->account_url);
free(a->avatar.url);
free(a->avatar.static_url);
free(a);
}
void account_save( struct account* a )

@ -72,5 +72,9 @@ void notification_write_as_json( struct notification* n, FILE* f )
struct status* s = status_from_id( n->status_id );
#include "src/model/notification.json.inc"
status_free(s);
account_free(owner);
account_free(a);
}

@ -38,7 +38,7 @@ struct timeline* timeline_block_load( int id, unsigned int head, unsigned int bl
if( !json_read_object_layout_from_file( filename, timeline_block_layout, tl ) ) {
free(tl);
return tl;
return NULL;
}
return tl;

Loading…
Cancel
Save