[Graph Libraries] Memory Leak through gvContextPlugins
Ported Issue from Mantis Original ID: 2214 Reported By: johannes
SEVERITY: MAJOR Submitted: 2012-03-26 09:12:06
OS: IOS
OS BUILD: 5.1
PLATFORM: IPAD
DESCRIPTION
There is a memory leak after calling gvContextPlugins when using Graphviz as a library on an iOS device. The leak is always reproducible (and is also in the Graphviz application for OS X). The amount of the leaked memory increases with the graph size.
STEPS TO REPRODUCE
- Building the library
- Using the Code below to load the symbols and use the library in the Objective-C program
/**************************************************************************************************
* builtins.c
* Defines the list of preloaded symbols, is supposed to be compiled and linked with the project
*/
#include "gvplugin.h"
extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
extern gvplugin_library_t gvplugin_neato_layout_LTX_library;
extern gvplugin_library_t gvplugin_core_LTX_library;
extern gvplugin_library_t gvplugin_quartz_LTX_library;
extern gvplugin_library_t gvplugin_visio_LTX_library;
lt_symlist_t lt_preloaded_symbols[] =
{
{ "gvplugin_dot_layout_LTX_library", &gvplugin_dot_layout_LTX_library},
{ "gvplugin_neato_layout_LTX_library", &gvplugin_neato_layout_LTX_library},
{ "gvplugin_core_LTX_library", &gvplugin_core_LTX_library},
{ "gvplugin_quartz_LTX_library", &gvplugin_quartz_LTX_library},
{ "gvplugin_visio_LTX_library", &gvplugin_visio_LTX_library},
{ 0, 0}
};
/**************************************************************************************************
* AppDelegate.m
* Reduced example with just the the needed method
*/
#import "AppDelegate.h"
#import "gvc.h"
@implementation AppDelegate
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// Graphviz Example
Agraph_t *g;
GVC_t *gvc;
// load the plugins from builtins.c; here the leak originates
gvc = gvContextPlugins(lt_preloaded_symbols, 0);
g = agopen("G", AGFLAG_DIRECTED);
// create three example nodes (two boxes, one hexagon)
Agnode_t *node1 = agnode(g, "Box 1");
agsafeset(node1, "shape", "box", "");
Agnode_t *node2 = agnode(g, "Hexagon 1");
agsafeset(node2, "shape", "hexagon", "");
Agnode_t *node3 = agnode(g, "Box 2");
agsafeset(node3, "shape", "box", "");
// connect the nodes
agedge(g, node1, node2);
agedge(g, node2, node3);
// layout graph
gvLayout(gvc, g, "dot");
// print layout
#if TARGET_IPHONE_SIMULATOR
NSLog(@"Can not write to stdout in simulator");
#else
agwrite(g, stdout);
#endif
// free memory
gvFreeLayout(gvc, g);
agclose(g);
return YES;
}
@end
Edited by Matthew Fernandez