1
0
Fork 0

Remove the last unnecessary alloc from the library

This commit is contained in:
ehofman 2008-06-30 12:00:40 +00:00
parent dd77cd25f6
commit f35ab314bf
3 changed files with 20 additions and 11 deletions

View file

@ -1,3 +1,8 @@
30-06-2008:
* some small changes; fix some typo's en fix a small memory leak
* update the documentation in README
* remove the last unnecessary alloc
29-06-2008: 29-06-2008:
* rename xmlGet(Int/Double/String) to xmlGetNode(Int/Double/String) * rename xmlGet(Int/Double/String) to xmlGetNode(Int/Double/String)
* add new xmlGet(Int/Double/String) functions * add new xmlGet(Int/Double/String) functions

View file

@ -1,5 +1,5 @@
/* Copyright (c) 2007, 2008 by Adalin B.V. /* Copyright (c) 2007,2008 by Adalin B.V.
* Copyright (c) 2007, 2008 by Erik Hofman * Copyright (c) 2007,2008 by Erik Hofman
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -60,7 +60,6 @@ void simple_unmmap(SIMPLE_UNMMAP *);
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
struct _xml_id struct _xml_id
{ {
char *start; char *start;
@ -124,6 +123,7 @@ xmlCopyNode(void *id, char *path)
char *ptr, *p; char *ptr, *p;
size_t rlen; size_t rlen;
rlen = strlen(path);
ptr = __xmlGetNode(xid->start, xid->len, path, &rlen); ptr = __xmlGetNode(xid->start, xid->len, path, &rlen);
if (ptr) if (ptr)
{ {
@ -155,6 +155,7 @@ xmlGetNode(void *id, char *path)
size_t rlen; size_t rlen;
char *ptr; char *ptr;
rlen = strlen(path);
ptr = __xmlGetNode(xid->start, xid->len, path, &rlen); ptr = __xmlGetNode(xid->start, xid->len, path, &rlen);
if (ptr) if (ptr)
{ {
@ -183,6 +184,7 @@ xmlGetNextElement(const void *pid, void *id, char *path)
if (xid->len < xpid->len) xid->start += xid->len; if (xid->len < xpid->len) xid->start += xid->len;
nlen = xpid->len - (xid->start - xpid->start); nlen = xpid->len - (xid->start - xpid->start);
rlen = strlen(path);
ptr = __xmlGetNode(xid->start, nlen, path, &rlen); ptr = __xmlGetNode(xid->start, nlen, path, &rlen);
if (ptr) if (ptr)
{ {
@ -220,6 +222,7 @@ xmlCompareNodeString(const void *id, const char *path, const char *s)
size_t rlen; size_t rlen;
char *str; char *str;
rlen = strlen(path);
str = __xmlGetNode(xid->start, xid->len, path, &rlen); str = __xmlGetNode(xid->start, xid->len, path, &rlen);
if (str) ret = strncasecmp(str, s, rlen); if (str) ret = strncasecmp(str, s, rlen);
} }
@ -303,6 +306,7 @@ xmlCopyString(void *id, const char *path, char *buffer, unsigned int buflen)
char *str; char *str;
*buffer = 0; *buffer = 0;
rlen = strlen(path);
str = __xmlGetNode(xid->start, xid->len, path, &rlen); str = __xmlGetNode(xid->start, xid->len, path, &rlen);
if (str) if (str)
{ {
@ -337,6 +341,7 @@ xmlGetNodeInt(void *id, const char *path)
unsigned int rlen; unsigned int rlen;
char *str; char *str;
rlen = strlen(path);
str = __xmlGetNode(xid->start, xid->len, path, &rlen); str = __xmlGetNode(xid->start, xid->len, path, &rlen);
if (str) li = strtol(str, (char **)NULL, 10); if (str) li = strtol(str, (char **)NULL, 10);
} }
@ -367,6 +372,7 @@ xmlGetNodeDouble(void *id, const char *path)
unsigned int rlen; unsigned int rlen;
char *str; char *str;
rlen = strlen(path);
str = __xmlGetNode(xid->start, xid->len, path, &rlen); str = __xmlGetNode(xid->start, xid->len, path, &rlen);
if (str) d = strtod(str, (char **)NULL); if (str) d = strtod(str, (char **)NULL);
@ -406,13 +412,8 @@ xmlGetNumElements(void *id, const char *path)
nname = strrchr(pathname, '/'); nname = strrchr(pathname, '/');
if (nname) if (nname)
{ {
unsigned int plen = nname-pathname; clen = nname-pathname;
pname = calloc(1, plen+1);
memcpy(pname, path, plen);
p = __xmlGetNode(xid->start, xid->len, pname, &clen); p = __xmlGetNode(xid->start, xid->len, pname, &clen);
free(pname);
} }
else else
{ {
@ -454,6 +455,7 @@ __xmlCopyNode(char *start, size_t len, const char *path)
char *p, *ret = 0; char *p, *ret = 0;
size_t rlen; size_t rlen;
rlen = strlen(path);
p = __xmlGetNode(start, len, path, &rlen); p = __xmlGetNode(start, len, path, &rlen);
if (p && rlen) if (p && rlen)
{ {
@ -482,7 +484,7 @@ __xmlGetNode(char *start, size_t len, const char *path, size_t *rlen)
if (!ptr) if (!ptr)
{ {
last_node = 1; last_node = 1;
ptr = name+strlen(name); ptr = name + *rlen;
} }
plen = ptr - name; plen = ptr - name;
@ -529,7 +531,9 @@ __xmlGetNode(char *start, size_t len, const char *path, size_t *rlen)
} }
} }
else else
{
ret = __xmlGetNode(cur, len, ptr+1, rlen); ret = __xmlGetNode(cur, len, ptr+1, rlen);
}
} }
} }
} }

View file

@ -45,7 +45,7 @@ show_help ()
void void
free_and_exit(int i) free_and_exit(int i)
{ {
if (_root != _static_root) free(_root); if (_root && _root != _static_root) free(_root);
if (_element) free(_element); if (_element) free(_element);
if (_value) free(_value); if (_value) free(_value);
if (_print) free(_print); if (_print) free(_print);