Skip to content

Commit

Permalink
add memory allocation checks to fastcci_build_db
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Feb 7, 2014
1 parent 611b7da commit b195404
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ LINK_DIRECTORIES(/usr/local/lib)
target_link_libraries(fastcci_server onion pthread)

# build the DB files
add_executable(fastcci fastcci.cc)
add_executable(fastcci_build_db fastcci_build_db.cc)

# command line inspection tools
add_executable(fastcci_circulartest fastcci_circulartest.cc)
add_executable(fastcci_intersection2 fastcci_intersection2.cc)
add_executable(fastcci_subcats fastcci_subcats.cc)
add_executable(fastcci_path fastcci_path.cc)

install (TARGETS fastcci_server fastcci DESTINATION /usr/bin COMPONENT binaries)
install (TARGETS fastcci_server fastcci_build_db DESTINATION /usr/bin COMPONENT binaries)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Fast Commons Category Inspection is an in-memory database for fast commons categ

FastCCI can operate without depth limits on categories.

```fastcci``` builds the binary database files form an SQL dump of the categorylinks database.
```fastcci_build_db``` builds the binary database files form an SQL dump of the categorylinks database.

```fastcci_server``` is the database server backend that can be queried through HTTP.

Expand All @@ -27,7 +27,7 @@ The text output is streamed into the ```fastcci``` command that parses it and ge
Both files are saved to the current directory.

```
mysql --defaults-file=$HOME/replica.my.cnf -h commonswiki.labsdb commonswiki_p -e 'select /* SLOW_OK */ cl_from, page_id, cl_type from categorylinks,page where cl_type!="page" and page_namespace=14 and page_title=cl_to order by page_id;' --quick --batch --silent | ./fastcci
mysql --defaults-file=$HOME/replica.my.cnf -h commonswiki.labsdb commonswiki_p -e 'select /* SLOW_OK */ cl_from, page_id, cl_type from categorylinks,page where cl_type!="page" and page_namespace=14 and page_title=cl_to order by page_id;' --quick --batch --silent | ./fastcci_build_db
```

## Query syntax
Expand Down
12 changes: 12 additions & 0 deletions fastcci.cc → fastcci_build_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ void growTree(int max=0) {
if (maxtree<=max) maxtree = max+1;
tree = (tree_type*)realloc(tree, maxtree * sizeof *tree);
}

// check for allocation error
if (tree==NULL) {
fprintf(stderr, "Out of memory in growTree()\n");
exit(1);
}
}

void growCat(int max=0) {
Expand All @@ -25,6 +31,12 @@ void growCat(int max=0) {
cat = (tree_type*)realloc(cat, maxcat * sizeof *cat);
}

// check for allocation error
if (cat==NULL) {
fprintf(stderr, "Out of memory in growCat()\n");
exit(1);
}

// initialize al cat entries to -1 (unused pageids are files)
for (int i=a; i<maxcat; ++i) cat[i] = -1;
}
Expand Down

0 comments on commit b195404

Please sign in to comment.